diff --git a/README.md b/README.md index 229a96a..a06ffb4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![NPM version](https://img.shields.io/npm/v/unplugin-unocss-config?color=a1b858&label=)](https://www.npmjs.com/package/unplugin-unocss-config) -Load your uno config and use it in run-time. +Use uno config in run-time. ## Usage diff --git a/packages/core/client.d.ts b/client.d.ts similarity index 100% rename from packages/core/client.d.ts rename to client.d.ts diff --git a/eslint.config.js b/eslint.config.mjs similarity index 100% rename from eslint.config.js rename to eslint.config.mjs diff --git a/package.json b/package.json index 8fcfbc3..925cd70 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,95 @@ { - "type": "module", + "name": "unplugin-unocss-config", "version": "0.1.0", - "private": true, - "packageManager": "pnpm@8.12.0", + "packageManager": "pnpm@9.9.0", + "description": "Use uno config in run-time", + "license": "MIT", + "homepage": "https://github.com/unpreset/unplugin-unocss-config#readme", + "repository": { + "type": "git", + "url": "git+https://github.com/unpreset/unplugin-unocss-config.git" + }, + "bugs": { + "url": "https://github.com/unpreset/unplugin-unocss-config/issues" + }, + "keywords": [ + "unpreset", + "unocss", + "unocss-config", + "unplugin", + "vite", + "nuxt-module" + ], + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.mjs", + "require": "./dist/index.js" + }, + "./client": { + "types": "./client.d.ts" + }, + "./vite": { + "types": "./dist/vite.d.ts", + "import": "./dist/vite.mjs", + "require": "./dist/vite.js" + }, + "./nuxt": { + "types": "./dist/nuxt.d.ts", + "import": "./dist/nuxt.mjs", + "require": "./dist/nuxt.js" + }, + "./types": { + "types": "./dist/types.d.ts", + "import": "./dist/types.mjs", + "require": "./dist/types.js" + }, + "./*": "./*" + }, + "main": "./dist/index.js", + "module": "./dist/index.mjs", + "types": "./dist/index.d.ts", + "typesVersions": { + "*": { + "*": [ + "./dist/*", + "./*" + ] + } + }, + "files": [ + "client.d.ts", + "dist" + ], "scripts": { - "dev": "pnpm -r --filter=./packages/* --parallel run dev", - "build": "pnpm -r --filter=./packages/* --parallel run build", + "build": "tsup", + "dev": "tsup --watch src", + "build:fix": "esno scripts/postbuild.ts", "lint": "eslint .", - "play": "pnpm -C playground run dev", - "prepublishOnly": "pnpm run build", - "release": "bumpp -r && pnpm -r publish --access public --no-git-checks" + "play": "npm -C playground run dev", + "prepublishOnly": "npm run build", + "release": "bumpp && npm publish", + "start": "esno src/index.ts", + "test": "vitest" + }, + "peerDependencies": { + "@nuxt/kit": "^3", + "@nuxt/schema": "^3", + "vite": ">=3" + }, + "peerDependenciesMeta": { + "@nuxt/kit": { + "optional": true + }, + "@nuxt/schema": { + "optional": true + }, + "vite": { + "optional": true + } + }, + "dependencies": { + "unplugin": "^1.5.1" }, "devDependencies": { "@antfu/eslint-config": "^2.6.1", diff --git a/packages/core/README.md b/packages/core/README.md deleted file mode 100644 index a06ffb4..0000000 --- a/packages/core/README.md +++ /dev/null @@ -1,72 +0,0 @@ -# unplugin-unocss-config - -[![NPM version](https://img.shields.io/npm/v/unplugin-unocss-config?color=a1b858&label=)](https://www.npmjs.com/package/unplugin-unocss-config) - -Use uno config in run-time. - -## Usage - -```html - -``` - -## Install - -```bash -pnpm add unplugin-unocss-config -``` - -
-Vite
- -```ts -// vite.config.ts -import UnoCSSConfig from 'unplugin-unocss-config/vite' - -export default defineConfig({ - plugins: [ - UnoCSSConfig(), - ], -}) -``` - -### Type -```ts -// vite-env.d.ts -/// -``` - -Example: [`playground/`](./playground/) - -
- -
-Nuxt
- -```ts -// nuxt.config.js -export default { - buildModules: [ - ['unplugin-unocss-config/nuxt', { /* options */ }], - ], -} -``` - -> This module works for both Nuxt 2 and [Nuxt Vite](https://github.com/nuxt/vite) - -
- -## License - -MIT License © 2023-PRESENT [Chris](https://github.com/zyyv) diff --git a/packages/core/package.json b/packages/core/package.json deleted file mode 100644 index 0daf907..0000000 --- a/packages/core/package.json +++ /dev/null @@ -1,91 +0,0 @@ -{ - "name": "unplugin-unocss-config", - "version": "0.1.0", - "description": "Use uno config in run-time", - "license": "MIT", - "homepage": "https://github.com/zyyv/unplugin-unocss-config#readme", - "repository": { - "type": "git", - "url": "git+https://github.com/zyyv/unplugin-unocss-config.git" - }, - "bugs": { - "url": "https://github.com/zyyv/unplugin-unocss-config/issues" - }, - "keywords": [ - "unpreset", - "unocss", - "unocss-config", - "unplugin", - "vite", - "nuxt-module" - ], - "exports": { - ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "require": "./dist/index.js" - }, - "./client": { - "types": "./client.d.ts" - }, - "./vite": { - "types": "./dist/vite.d.ts", - "import": "./dist/vite.mjs", - "require": "./dist/vite.js" - }, - "./nuxt": { - "types": "./dist/nuxt.d.ts", - "import": "./dist/nuxt.mjs", - "require": "./dist/nuxt.js" - }, - "./types": { - "types": "./dist/types.d.ts", - "import": "./dist/types.mjs", - "require": "./dist/types.js" - }, - "./*": "./*" - }, - "main": "./dist/index.js", - "module": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "typesVersions": { - "*": { - "*": [ - "./dist/*", - "./*" - ] - } - }, - "files": [ - "client.d.ts", - "dist" - ], - "scripts": { - "build": "tsup", - "dev": "tsup --watch src", - "build:fix": "esno scripts/postbuild.ts" - }, - "peerDependencies": { - "@nuxt/kit": "^3", - "@nuxt/schema": "^3", - "vite": ">=3" - }, - "peerDependenciesMeta": { - "@nuxt/kit": { - "optional": true - }, - "@nuxt/schema": { - "optional": true - }, - "vite": { - "optional": true - } - }, - "dependencies": { - "unplugin": "^1.5.1" - }, - "devDependencies": { - "@unocss/config": "^0.62.3", - "@unocss/core": "^0.62.3" - } -} diff --git a/packages/core/src/nuxt.ts b/packages/core/src/nuxt.ts deleted file mode 100644 index d3173b3..0000000 --- a/packages/core/src/nuxt.ts +++ /dev/null @@ -1,16 +0,0 @@ -import type { Options } from './types' -import unplugin from '.' - -export default function (options: Options = {}, nuxt: any) { - // install webpack plugin - nuxt.hook('webpack:config', async (config: any) => { - config.plugins = config.plugins || [] - config.plugins.unshift(unplugin.webpack(options)) - }) - - // install vite plugin - nuxt.hook('vite:extendConfig', async (config: any) => { - config.plugins = config.plugins || [] - config.plugins.push(unplugin.vite(options)) - }) -} diff --git a/packages/core/src/vite.ts b/packages/core/src/vite.ts deleted file mode 100644 index 589f4b9..0000000 --- a/packages/core/src/vite.ts +++ /dev/null @@ -1,3 +0,0 @@ -import unplugin from '.' - -export default unplugin.vite diff --git a/playground/package.json b/playground/package.json index c2f959e..db26bb8 100644 --- a/playground/package.json +++ b/playground/package.json @@ -1,4 +1,5 @@ { + "type": "module", "private": true, "scripts": { "dev": "cross-env DEBUG=unplugin-unocss-config vite", diff --git a/playground/tsconfig.json b/playground/tsconfig.json deleted file mode 100644 index 4cd8797..0000000 --- a/playground/tsconfig.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "extends": "../tsconfig.json", - "compilerOptions": { - "target": "esnext", - "jsx": "preserve", - "lib": ["esnext", "dom"], - "module": "esnext", - "resolveJsonModule": true, - "types": [ - "vite/client", - "unplugin-unocss-config/client" - ], - "strict": true, - "sourceMap": true, - "esModuleInterop": true - }, - "exclude": [ - "**/dist/**", - "**/node_modules/**" - ] -} diff --git a/playground/vite.config.ts b/playground/vite.config.mts similarity index 83% rename from playground/vite.config.ts rename to playground/vite.config.mts index 5b047b4..4316dc6 100644 --- a/playground/vite.config.ts +++ b/playground/vite.config.mts @@ -2,7 +2,7 @@ import { defineConfig } from 'vite' import Inspect from 'vite-plugin-inspect' import vue from '@vitejs/plugin-vue' import UnoCSS from 'unocss/vite' -import Unplugin from 'unplugin-unocss-config/vite' +import Unplugin from '../src/vite' export default defineConfig({ plugins: [ diff --git a/packages/core/scripts/postbuild.ts b/scripts/postbuild.ts similarity index 100% rename from packages/core/scripts/postbuild.ts rename to scripts/postbuild.ts diff --git a/packages/core/src/index.ts b/src/index.ts similarity index 76% rename from packages/core/src/index.ts rename to src/index.ts index 05f5a64..c981408 100644 --- a/packages/core/src/index.ts +++ b/src/index.ts @@ -1,10 +1,9 @@ -import { createUnplugin } from 'unplugin' import { createGenerator } from '@unocss/core' import { loadConfig } from '@unocss/config' -import type { ViteDevServer } from 'vite' +import { type UnpluginFactory, createUnplugin } from 'unplugin' import type { Options } from './types' -export default createUnplugin((options) => { +export const unpluginFactory: UnpluginFactory = (options) => { let uno: ReturnType return { @@ -26,10 +25,9 @@ export default createUnplugin((options) => { }, } }, - configureServer(server: ViteDevServer) { - // 监听 uno.config.js 文件变化 + configureServer(server) { server.watcher.on('change', async (path) => { - if (path.endsWith('uno.config.ts')) { + if (path.includes('uno.config.')) { uno = createGenerator((await loadConfig(server.config.root, options?.path)).config) server.ws.send({ type: 'custom', @@ -41,4 +39,8 @@ export default createUnplugin((options) => { }, }, } -}) +} + +export const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory) + +export default unplugin diff --git a/src/nuxt.ts b/src/nuxt.ts new file mode 100644 index 0000000..61eeffc --- /dev/null +++ b/src/nuxt.ts @@ -0,0 +1,21 @@ +import { addVitePlugin, defineNuxtModule } from '@nuxt/kit' +import vite from './vite' +import type { Options } from './types' +import '@nuxt/schema' + +export interface ModuleOptions extends Options { + +} + +export default defineNuxtModule({ + meta: { + name: 'nuxt-unplugin-starter', + configKey: 'unpluginStarter', + }, + defaults: { + // ...default options + }, + setup(options, _nuxt) { + addVitePlugin(() => vite(options)) + }, +}) diff --git a/packages/core/src/types.ts b/src/types.ts similarity index 100% rename from packages/core/src/types.ts rename to src/types.ts diff --git a/src/vite.ts b/src/vite.ts new file mode 100644 index 0000000..151a5ce --- /dev/null +++ b/src/vite.ts @@ -0,0 +1,4 @@ +import { createVitePlugin } from 'unplugin' +import { unpluginFactory } from '.' + +export default createVitePlugin(unpluginFactory) diff --git a/tsconfig.json b/tsconfig.json index 4971fb9..acc4e44 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,17 +5,13 @@ "module": "esnext", "moduleResolution": "node", "resolveJsonModule": true, + "types": [ + "vite/client", + "./client" + ], "strict": true, "strictNullChecks": true, "esModuleInterop": true }, - "exclude": [ - "**/dist/**", - "**/node_modules/**", - "**/playground/**", - "**/examples/**", - "**/fixtures/**", - "**/test/dts/**", - "**/*.js" - ] + "exclude": ["dist", "eslint.config.mjs"] } diff --git a/packages/core/tsup.config.ts b/tsup.config.ts similarity index 92% rename from packages/core/tsup.config.ts rename to tsup.config.ts index f46ba0f..fc57fa9 100644 --- a/packages/core/tsup.config.ts +++ b/tsup.config.ts @@ -7,6 +7,5 @@ export default { clean: true, format: ['cjs', 'esm'], dts: true, - shims: true, onSuccess: 'npm run build:fix', }