Skip to content

Commit

Permalink
refactor: update
Browse files Browse the repository at this point in the history
  • Loading branch information
zyyv committed Aug 27, 2024
1 parent 0f5725b commit 9e7f8a1
Show file tree
Hide file tree
Showing 18 changed files with 130 additions and 230 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
File renamed without changes.
File renamed without changes.
96 changes: 88 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,95 @@
{
"type": "module",
"name": "unplugin-unocss-config",
"version": "0.1.0",
"private": true,
"packageManager": "[email protected]",
"packageManager": "[email protected]",
"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",
Expand Down
72 changes: 0 additions & 72 deletions packages/core/README.md

This file was deleted.

91 changes: 0 additions & 91 deletions packages/core/package.json

This file was deleted.

16 changes: 0 additions & 16 deletions packages/core/src/nuxt.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/core/src/vite.ts

This file was deleted.

1 change: 1 addition & 0 deletions playground/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"type": "module",
"private": true,
"scripts": {
"dev": "cross-env DEBUG=unplugin-unocss-config vite",
Expand Down
21 changes: 0 additions & 21 deletions playground/tsconfig.json

This file was deleted.

2 changes: 1 addition & 1 deletion playground/vite.config.ts → playground/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
File renamed without changes.
16 changes: 9 additions & 7 deletions packages/core/src/index.ts → src/index.ts
Original file line number Diff line number Diff line change
@@ -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 | undefined>((options) => {
export const unpluginFactory: UnpluginFactory<Options | undefined> = (options) => {
let uno: ReturnType<typeof createGenerator>

return {
Expand All @@ -26,10 +25,9 @@ export default createUnplugin<Options | undefined>((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',
Expand All @@ -41,4 +39,8 @@ export default createUnplugin<Options | undefined>((options) => {
},
},
}
})
}

export const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)

export default unplugin
21 changes: 21 additions & 0 deletions src/nuxt.ts
Original file line number Diff line number Diff line change
@@ -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<ModuleOptions>({
meta: {
name: 'nuxt-unplugin-starter',
configKey: 'unpluginStarter',
},
defaults: {
// ...default options
},
setup(options, _nuxt) {
addVitePlugin(() => vite(options))
},
})
File renamed without changes.
4 changes: 4 additions & 0 deletions src/vite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createVitePlugin } from 'unplugin'
import { unpluginFactory } from '.'

export default createVitePlugin(unpluginFactory)
Loading

0 comments on commit 9e7f8a1

Please sign in to comment.