From 7ae82300a048ee910c66629a8ebb3a104b6c26e6 Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Fri, 12 Aug 2022 01:10:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(plugin-windicss):=20=E6=96=B0=E5=A2=9Ewind?= =?UTF-8?q?icss=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 4 +- packages/plugin-windicss/LICENSE | 21 +++ packages/plugin-windicss/README.md | 27 ++++ packages/plugin-windicss/package.json | 53 ++++++++ .../plugin-windicss/src/client/config.vite.ts | 5 + .../src/client/config.webpack.ts | 5 + packages/plugin-windicss/src/node/index.ts | 5 + packages/plugin-windicss/src/node/plugin.ts | 47 +++++++ packages/plugin-windicss/tsconfig.build.json | 12 ++ packages/plugin-windicss/tsconfig.cjs.json | 9 ++ packages/plugin-windicss/tsconfig.esm.json | 10 ++ pnpm-lock.yaml | 125 ++++++++++++++++-- 12 files changed, 308 insertions(+), 15 deletions(-) create mode 100644 packages/plugin-windicss/LICENSE create mode 100644 packages/plugin-windicss/README.md create mode 100644 packages/plugin-windicss/package.json create mode 100644 packages/plugin-windicss/src/client/config.vite.ts create mode 100644 packages/plugin-windicss/src/client/config.webpack.ts create mode 100644 packages/plugin-windicss/src/node/index.ts create mode 100644 packages/plugin-windicss/src/node/plugin.ts create mode 100644 packages/plugin-windicss/tsconfig.build.json create mode 100644 packages/plugin-windicss/tsconfig.cjs.json create mode 100644 packages/plugin-windicss/tsconfig.esm.json diff --git a/.vscode/settings.json b/.vscode/settings.json index 54e60eac..d5ec9547 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -34,6 +34,8 @@ "tsbuildinfo", "vite", "vuepress", - "vueuse" + "vueuse", + "Windi", + "Windicss" ] } diff --git a/packages/plugin-windicss/LICENSE b/packages/plugin-windicss/LICENSE new file mode 100644 index 00000000..9f677c90 --- /dev/null +++ b/packages/plugin-windicss/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (C) 2021 - PRESENT by pengzhanbo + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/packages/plugin-windicss/README.md b/packages/plugin-windicss/README.md new file mode 100644 index 00000000..6988209d --- /dev/null +++ b/packages/plugin-windicss/README.md @@ -0,0 +1,27 @@ +# `@vuepress-plume/vuepress-plugin-windicss` + +添加 `windicss` 支持 + +## Install +``` +yarn add @vuepress-plume/vuepress-plugin-windicss +``` +## Usage +``` js +// .vuepress/config.js +module.exports = { + //... + plugins: [ + windicssPlugin(options) + ] + // ... +} +``` + +## Method + +`windicssPlugin(options)` + +- `options`: `{ userOptions?: UserOptions; utilsOptions?: WindiPluginUtilsOptions } | string` + + windicss 配置文件路径,或者 windicss配置 diff --git a/packages/plugin-windicss/package.json b/packages/plugin-windicss/package.json new file mode 100644 index 00000000..9285544c --- /dev/null +++ b/packages/plugin-windicss/package.json @@ -0,0 +1,53 @@ +{ + "name": "@vuepress-plume/vuepress-plugin-windicss", + "version": "1.0.0-beta.39", + "description": "The Plugin for VuePres 2", + "homepage": "https://github.com/pengzhanbo/vuepress-theme-plume#readme", + "bugs": { + "url": "https://github.com/pengzhanbo/vuepress-theme-plume/issues" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/pengzhanbo/vuepress-theme-plume.git" + }, + "license": "MIT", + "author": "pengzhanbo ", + "main": "lib/node/index.js", + "files": [ + "lib" + ], + "scripts": { + "build": "pnpm run clean && pnpm run copy && pnpm run ts", + "clean": "rimraf lib *.tsbuildinfo", + "copy": "cpx \"src/**/*.{d.ts,vue,css,scss,jpg,png}\" lib", + "copy:watch": "cpx \"src/**/*.{d.ts,vue,css,scss,jpg,png}\" lib -w", + "dev": "concurrently \"pnpm copy:watch\" \"pnpm ts:watch\"", + "ts": "tsc -b tsconfig.build.json", + "ts:watch": "tsc -b tsconfig.build.json --watch" + }, + "dependencies": { + "@vuepress/client": "2.0.0-beta.49", + "@vuepress/core": "2.0.0-beta.49", + "@vuepress/shared": "2.0.0-beta.49", + "@vuepress/utils": "2.0.0-beta.49", + "vite-plugin-windicss": "^1.8.7", + "windicss": "^3.5.6", + "windicss-webpack-plugin": "^1.7.5" + }, + "publishConfig": { + "access": "public" + }, + "keyword": [ + "VuePress", + "vuepress plugin", + "Windicss", + "vuepress-plugin-windicss" + ], + "pnpm": { + "peerDependencyRules": { + "ignoreMissing": [ + "vite" + ] + } + } +} diff --git a/packages/plugin-windicss/src/client/config.vite.ts b/packages/plugin-windicss/src/client/config.vite.ts new file mode 100644 index 00000000..0bf9dc52 --- /dev/null +++ b/packages/plugin-windicss/src/client/config.vite.ts @@ -0,0 +1,5 @@ +import { defineClientConfig } from '@vuepress/client' + +import 'virtual:windi.css' + +export default defineClientConfig({}) diff --git a/packages/plugin-windicss/src/client/config.webpack.ts b/packages/plugin-windicss/src/client/config.webpack.ts new file mode 100644 index 00000000..1c378c86 --- /dev/null +++ b/packages/plugin-windicss/src/client/config.webpack.ts @@ -0,0 +1,5 @@ +import { defineClientConfig } from '@vuepress/client' + +import 'windi.css' + +export default defineClientConfig({}) diff --git a/packages/plugin-windicss/src/node/index.ts b/packages/plugin-windicss/src/node/index.ts new file mode 100644 index 00000000..e280eadc --- /dev/null +++ b/packages/plugin-windicss/src/node/index.ts @@ -0,0 +1,5 @@ +import { windiCSSPlugin } from './plugin' + +export * from './plugin' + +export default windiCSSPlugin diff --git a/packages/plugin-windicss/src/node/plugin.ts b/packages/plugin-windicss/src/node/plugin.ts new file mode 100644 index 00000000..6d559b32 --- /dev/null +++ b/packages/plugin-windicss/src/node/plugin.ts @@ -0,0 +1,47 @@ +import type { App, Plugin } from '@vuepress/core' +import { path } from '@vuepress/utils' +import type { UserOptions, WindiPluginUtilsOptions } from 'vite-plugin-windicss' +import viteWindiCSS from 'vite-plugin-windicss' +import WebpackWindiCSSPlugin from 'windicss-webpack-plugin' + +export interface WindiCSSOptions { + userOptions?: UserOptions + utilsOptions?: WindiPluginUtilsOptions +} + +export const windiCSSPlugin = (options?: WindiCSSOptions | string): Plugin => { + let userOptions: UserOptions | undefined + let utilsOptions: WindiPluginUtilsOptions | undefined + if (typeof options === 'string') { + userOptions = { config: options } + } else { + options = options || {} + userOptions = options.userOptions + utilsOptions = options.utilsOptions + } + return (app: App) => { + const clientConfigFile = + app.options.bundler.name === '@vuepress/bundler-vite' + ? path.resolve(__dirname, '../client/config.vite.js') + : path.resolve(__dirname, '../client/config.webpack.js') + return { + name: '@vuepress-plume/vuepress-plugin-windicss', + clientConfigFile, + extendsBundlerOptions: (bundlerOptions, app: App) => { + if (app.options.bundler.name === '@vuepress/bundler-vite') { + bundlerOptions.viteOptions ??= {} + bundlerOptions.viteOptions.plugins ??= [] + bundlerOptions.viteOptions.plugins.push( + viteWindiCSS(userOptions, utilsOptions) + ) + } + if (app.options.bundler.name === '@vuepress/bundler-webpack') { + bundlerOptions.configureWebpack && + bundlerOptions.configureWebpack((config: any) => { + config.plugins.push(new WebpackWindiCSSPlugin(userOptions)) + }) + } + }, + } + } +} diff --git a/packages/plugin-windicss/tsconfig.build.json b/packages/plugin-windicss/tsconfig.build.json new file mode 100644 index 00000000..b373aff3 --- /dev/null +++ b/packages/plugin-windicss/tsconfig.build.json @@ -0,0 +1,12 @@ +{ + "extends": "../../tsconfig.base.json", + "references": [ + { + "path": "./tsconfig.esm.json" + }, + { + "path": "./tsconfig.cjs.json" + } + ], + "files": [] +} diff --git a/packages/plugin-windicss/tsconfig.cjs.json b/packages/plugin-windicss/tsconfig.cjs.json new file mode 100644 index 00000000..2d998114 --- /dev/null +++ b/packages/plugin-windicss/tsconfig.cjs.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "module": "CommonJS", + "rootDir": "./src", + "outDir": "./lib" + }, + "include": ["./src/node", "./src/shared"] +} diff --git a/packages/plugin-windicss/tsconfig.esm.json b/packages/plugin-windicss/tsconfig.esm.json new file mode 100644 index 00000000..6ddae220 --- /dev/null +++ b/packages/plugin-windicss/tsconfig.esm.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "module": "ES2020", + "rootDir": "./src", + "outDir": "./lib", + "types": ["@vuepress/client/types"] + }, + "include": ["./src/client", "./src/shared"] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c7177995..ce724cfb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -185,6 +185,24 @@ importers: vue: 3.2.37 vue-router: 4.1.2_vue@3.2.37 + packages/plugin-windicss: + specifiers: + '@vuepress/client': 2.0.0-beta.49 + '@vuepress/core': 2.0.0-beta.49 + '@vuepress/shared': 2.0.0-beta.49 + '@vuepress/utils': 2.0.0-beta.49 + vite-plugin-windicss: ^1.8.7 + windicss: ^3.5.6 + windicss-webpack-plugin: ^1.7.5 + dependencies: + '@vuepress/client': 2.0.0-beta.49 + '@vuepress/core': 2.0.0-beta.49 + '@vuepress/shared': 2.0.0-beta.49 + '@vuepress/utils': 2.0.0-beta.49 + vite-plugin-windicss: 1.8.7 + windicss: 3.5.6 + windicss-webpack-plugin: 1.7.5 + packages/theme: specifiers: '@types/lodash.merge': ^4.6.6 @@ -384,6 +402,10 @@ packages: '@jridgewell/trace-mapping': 0.3.14 dev: false + /@antfu/utils/0.5.2: + resolution: {integrity: sha512-CQkeV+oJxUazwjlHD0/3ZD08QWKuGQkhnrKo3e6ly5pd48VUpXbb77q0xMU4+vc2CkJnDS02Eq/M9ugyX20XZA==} + dev: false + /@babel/code-frame/7.18.6: resolution: {integrity: sha512-TDCmlK5eOvH+eH7cdAFlNXeVJqWIQ7gW9tY1GJIpUtFb6CmjVyq2VM3u71bOyR8CRihcCgMUYoDNyLXao3+70Q==} engines: {node: '>=6.9.0'} @@ -2313,7 +2335,7 @@ packages: /@types/sax/1.2.4: resolution: {integrity: sha512-pSAff4IAxJjfAXUG6tFkO7dsSbTmf8CtUpfhhZ5VhkRpC4628tJhh3+V6H1E+/Gs9piSzYKT5yzHO5M4GG9jkw==} dependencies: - '@types/node': 17.0.45 + '@types/node': 18.6.3 dev: false /@types/semver/7.3.10: @@ -3118,6 +3140,30 @@ packages: '@xtuc/long': 4.2.2 dev: false + /@windicss/config/1.8.7: + resolution: {integrity: sha512-8n+/Y36j5L3rw2tgMdLjeGRuNV7VYfKoHoraLK6Bk9OJ1MTPd5vv7pekof/uOPWVV7WWjVeZ6CTO8SDbDDW3iw==} + dependencies: + debug: 4.3.4 + jiti: 1.14.0 + windicss: 3.5.6 + transitivePeerDependencies: + - supports-color + dev: false + + /@windicss/plugin-utils/1.8.7: + resolution: {integrity: sha512-dfj95olNZyGFDPFMBvE5oq8hA5f0ooUJZjVdWlthS4ek4W1/xNOHDxB6ygWR8LE9zCOXZykApjt1LOhy9Ky2QA==} + dependencies: + '@antfu/utils': 0.5.2 + '@windicss/config': 1.8.7 + debug: 4.3.4 + fast-glob: 3.2.11 + magic-string: 0.26.2 + micromatch: 4.0.5 + windicss: 3.5.6 + transitivePeerDependencies: + - supports-color + dev: false + /@xtuc/ieee754/1.2.0: resolution: {integrity: sha512-DX8nKgqcGwsc0eJSqYt5lwP4DH5FlHnmuWWBRy7X0NcaGR0ZtuyeESgMwTYVEtxmsNGY+qit4QYT/MIYTOTPeA==} dev: false @@ -7496,18 +7542,6 @@ packages: debug: 2.6.9 dev: false - /follow-redirects/1.15.1_debug@4.3.4: - resolution: {integrity: sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==} - engines: {node: '>=4.0'} - peerDependencies: - debug: '*' - peerDependenciesMeta: - debug: - optional: true - dependencies: - debug: 4.3.4 - dev: false - /for-in/1.0.2: resolution: {integrity: sha512-7EwmXrOjyL+ChxMhmG5lnW9MPt1aIeZEwKhQzoBUdTV0N3zuwWDZYVJatDvZ2OyzPUvdIAZDsCetk3coyMfcnQ==} engines: {node: '>=0.10.0'} @@ -7692,6 +7726,11 @@ packages: engines: {node: '>=8'} dev: false + /get-port/6.1.2: + resolution: {integrity: sha512-BrGGraKm2uPqurfGVj/z97/zv8dPleC6x9JBNRTrDNtCkkRF4rPwrQXFgL7+I+q8QSdU4ntLQX2D7KIxSy8nGw==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dev: false + /get-stream/2.3.1: resolution: {integrity: sha512-AUGhbbemXxrZJRD5cDvKtQxLuYaIbNtDTK8YqupCI393Q2KSTreEsLUN3ZxAWFGiKTzL6nKuzfcIvieflUX9qA==} engines: {node: '>=0.10.0'} @@ -8427,7 +8466,7 @@ packages: engines: {node: '>=8.0.0'} dependencies: eventemitter3: 4.0.7 - follow-redirects: 1.15.1_debug@4.3.4 + follow-redirects: 1.15.1_debug@2.6.9 requires-port: 1.0.0 transitivePeerDependencies: - debug @@ -9109,6 +9148,11 @@ packages: supports-color: 8.1.1 dev: false + /jiti/1.14.0: + resolution: {integrity: sha512-4IwstlaKQc9vCTC+qUXLM1hajy2ImiL9KnLvVYiaHOtS/v3wRjhLlGl121AmgDgx/O43uKmxownJghS5XMya2A==} + hasBin: true + dev: false + /joycon/3.1.1: resolution: {integrity: sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==} engines: {node: '>=10'} @@ -9319,6 +9363,10 @@ packages: engines: {node: '>= 8'} dev: false + /kolorist/1.5.1: + resolution: {integrity: sha512-lxpCM3HTvquGxKGzHeknB/sUjuVoUElLlfYnXZT73K8geR9jQbroGlSCFBax9/0mpGoD3kzcMLnOlGQPJJNyqQ==} + dev: false + /kuler/2.0.0: resolution: {integrity: sha512-Xq9nH7KlWZmXAtodXDDRE7vs6DU1gTU8zYDHDiWLSip45Egwq3plLHzPn27NgvzL2r1LMPC1vdqh98sQxtqj4A==} dev: false @@ -9800,6 +9848,13 @@ packages: sourcemap-codec: 1.4.8 dev: false + /magic-string/0.26.2: + resolution: {integrity: sha512-NzzlXpclt5zAbmo6h6jNc8zl2gNRGHvmsZW4IvZhTC4W7k4OlLP+S5YLussa/r3ixNT66KOQfNORlXHSOy/X4A==} + engines: {node: '>=12'} + dependencies: + sourcemap-codec: 1.4.8 + dev: false + /make-array/1.0.5: resolution: {integrity: sha512-sgK2SAzxT19rWU+qxKUcn6PAh/swiIiz2F8C2cZjLc1z4iwYIfdoihqFIDQ8BDzAGtWPYJ6Sr13K1j/DXynDLA==} engines: {node: '>=0.10.0'} @@ -11216,6 +11271,10 @@ packages: engines: {node: '>=12'} dev: false + /pathe/0.2.0: + resolution: {integrity: sha512-sTitTPYnn23esFR3RlqYBWn4c45WGeLcsKzQiUpXJAyfcWkolvlYpV8FLo7JishK946oQwMFUCHXQ9AjGPKExw==} + dev: false + /pend/1.2.0: resolution: {integrity: sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==} dev: false @@ -13533,6 +13592,19 @@ packages: engines: {node: '>= 0.8'} dev: false + /vite-plugin-windicss/1.8.7: + resolution: {integrity: sha512-/zwQ8+RV+MSkbG0IGqsEma6r2R01NzN/aNpNjJD7VVAkxAptNznqDXOObFTskkWfZ+9m6KJZCOuCPgAFtQIzEA==} + peerDependencies: + vite: ^2.0.1 || ^3.0.0 + dependencies: + '@windicss/plugin-utils': 1.8.7 + debug: 4.3.4 + kolorist: 1.5.1 + windicss: 3.5.6 + transitivePeerDependencies: + - supports-color + dev: false + /vite/2.9.14: resolution: {integrity: sha512-P/UCjSpSMcE54r4mPak55hWAZPlyfS369svib/gpmz8/01L822lMPOJ/RYW6tLCe1RPvMvOsJ17erf55bKp4Hw==} engines: {node: '>=12.2.0'} @@ -13906,6 +13978,10 @@ packages: engines: {node: '>=10.13.0'} dev: false + /webpack-virtual-modules/0.4.4: + resolution: {integrity: sha512-h9atBP/bsZohWpHnr+2sic8Iecb60GxftXsWNLLLSqewgIsGzByd2gcIID4nXcG+3tNe4GQG3dLcff3kXupdRA==} + dev: false + /webpack/5.74.0: resolution: {integrity: sha512-A2InDwnhhGN4LYctJj6M1JEaGL7Luj6LOmyBHjcI8529cm5p6VXiTIW2sn6ffvEAKmveLzvu4jrihwXtPojlAA==} engines: {node: '>=10.13.0'} @@ -14013,6 +14089,27 @@ packages: resolution: {integrity: sha512-JcKqAHLPxcdb9KM49dufGXn2x3ssnfjbcaQdLlfZsL9rH9wgDQjUtDxbo8NE0F6SFvydeu1VhZe7hZuHsB2/pw==} dev: false + /windicss-webpack-plugin/1.7.5: + resolution: {integrity: sha512-+DwZwFcjgYrD/UU1UEs1TOTo4ijAwRkXEgJMttPd05NSC3ULvguvNKL5kNxrCTYs4OMJn68qbCfkjpI0mir4cQ==} + dependencies: + '@windicss/plugin-utils': 1.8.7 + debug: 4.3.4 + get-port: 6.1.2 + loader-utils: 2.0.2 + lodash: 4.17.21 + pathe: 0.2.0 + webpack-virtual-modules: 0.4.4 + windicss: 3.5.6 + transitivePeerDependencies: + - supports-color + dev: false + + /windicss/3.5.6: + resolution: {integrity: sha512-P1mzPEjgFMZLX0ZqfFht4fhV/FX8DTG7ERG1fBLiWvd34pTLVReS5CVsewKn9PApSgXnVfPWwvq+qUsRwpnwFA==} + engines: {node: '>= 12'} + hasBin: true + dev: false + /window-size/0.1.4: resolution: {integrity: sha512-2thx4pB0cV3h+Bw7QmMXcEbdmOzv9t0HFplJH/Lz6yu60hXYy5RT8rUu+wlIreVxWsGN20mo+MHeCSfUpQBwPw==} engines: {node: '>= 0.10.0'}