├── .husky ├── _ │ ├── .gitignore │ └── husky.sh ├── pre-commit └── commit-msg ├── .npmrc ├── packages ├── create-vite-lib-starter │ ├── .npmignore │ ├── _husky │ │ ├── pre-commit │ │ └── commit-msg │ ├── _npmrc │ ├── docs │ │ ├── en │ │ │ ├── guide │ │ │ │ └── introduction.md │ │ │ ├── api │ │ │ │ ├── entry.md │ │ │ │ ├── index.md │ │ │ │ ├── noop.md │ │ │ │ └── isNil.md │ │ │ └── index.md │ │ ├── zh │ │ │ ├── guide │ │ │ │ └── introduction.md │ │ │ ├── api │ │ │ │ ├── entry.md │ │ │ │ ├── index.md │ │ │ │ ├── noop.md │ │ │ │ └── isNil.md │ │ │ └── index.md │ │ └── .vitepress │ │ │ ├── cache │ │ │ └── deps │ │ │ │ ├── package.json │ │ │ │ ├── vue.js.map │ │ │ │ └── _metadata.json │ │ │ ├── config │ │ │ ├── index.mts │ │ │ ├── en.mts │ │ │ └── zh.mts │ │ │ └── theme │ │ │ └── index.ts │ ├── _eslintignore │ ├── commitlint.config.js │ ├── src │ │ ├── index.ts │ │ ├── noop.ts │ │ └── isNil.ts │ ├── tsconfig.typedoc.json │ ├── _lintstagedrc │ ├── tsconfig.json │ ├── tsconfig.build.json │ ├── _eslintrc │ ├── typedoc.json │ ├── typedoc.zh.json │ ├── vite.config.mts │ ├── tsconfig.base.json │ ├── bin │ │ └── index.mjs │ ├── test │ │ └── index.test.ts │ └── README.md ├── cs-runtime-helper │ ├── src │ │ ├── index.ts │ │ └── generateStarter.ts │ ├── tsconfig.build.json │ ├── README.md │ ├── vite.config.mts │ ├── LICENSE │ └── package.json ├── vite-plugin-external │ ├── src │ │ └── common │ │ │ ├── constants.ts │ │ │ └── logger.ts │ ├── tsconfig.build.json │ ├── vite.config.mts │ ├── LICENSE │ └── package.json ├── vite-plugin-view │ ├── src │ │ └── logger.ts │ ├── tsconfig.build.json │ ├── vite.config.mts │ ├── LICENSE │ └── package.json ├── vite-plugin-combine │ ├── src │ │ └── logger.ts │ ├── tsconfig.build.json │ ├── vite.config.mts │ └── LICENSE ├── vite-plugin-cp │ ├── src │ │ ├── logger.ts │ │ └── util.ts │ ├── tsconfig.build.json │ ├── vite.config.mts │ ├── LICENSE │ └── package.json ├── vite-plugin-mock-data │ ├── src │ │ ├── logger.ts │ │ └── types.ts │ ├── tsconfig.build.json │ ├── vite.config.mts │ ├── LICENSE │ ├── README.md │ └── package.json ├── vite-plugin-separate-importer │ ├── src │ │ └── logger.ts │ ├── tsconfig.build.json │ ├── vite.config.mts │ ├── LICENSE │ ├── package.json │ └── README.md ├── vite-plugin-hook-use │ ├── tsconfig.build.json │ ├── vite.config.mts │ ├── LICENSE │ └── package.json ├── vp-runtime-helper │ ├── tsconfig.build.json │ ├── src │ │ ├── colorful.ts │ │ ├── hash.ts │ │ ├── time.ts │ │ ├── devServer.ts │ │ ├── logger.ts │ │ └── index.ts │ ├── README.md │ ├── vite.config.mts │ ├── LICENSE │ └── package.json ├── vite-plugin-build-chunk │ ├── tsconfig.build.json │ ├── vite.config.mts │ ├── LICENSE │ ├── package.json │ └── src │ │ └── types.ts ├── vite-plugin-include-css │ ├── tsconfig.build.json │ ├── vite.config.mts │ ├── LICENSE │ └── package.json └── vite-plugin-reverse-proxy │ ├── tsconfig.build.json │ ├── vite.config.mts │ ├── LICENSE │ └── package.json ├── pnpm-workspace.yaml ├── commitlint.config.js ├── .eslintignore ├── examples ├── vite6-demo │ ├── custom-modules.d.ts │ ├── src │ │ ├── util │ │ │ ├── typings.ts │ │ │ ├── normalize.js │ │ │ ├── noop.ts │ │ │ ├── isDate.ts │ │ │ ├── outputFileSync.js │ │ │ ├── isNil.ts │ │ │ ├── isError.ts │ │ │ ├── outputFile.js │ │ │ ├── isNumber.ts │ │ │ └── isAsyncFunction.ts │ │ ├── separate-importer.jsx │ │ ├── index.jsx │ │ └── index2.jsx │ ├── v │ │ ├── main.ts │ │ └── App.vue │ ├── r │ │ ├── index.jsx │ │ ├── index2.jsx │ │ └── App.jsx │ ├── tsconfig.build.json │ ├── mock │ │ └── test.ts │ ├── index3.html │ ├── index.pug │ └── index.css ├── vite3-demo │ ├── src │ │ ├── custom-modules.d.ts │ │ ├── util │ │ │ ├── typings.ts │ │ │ ├── normalize.js │ │ │ ├── noop.ts │ │ │ ├── isDate.ts │ │ │ ├── outputFileSync.js │ │ │ ├── isNil.ts │ │ │ ├── isError.ts │ │ │ ├── outputFile.js │ │ │ ├── isNumber.ts │ │ │ └── isAsyncFunction.ts │ │ └── separate-importer.jsx │ ├── v │ │ ├── main.ts │ │ └── App.vue │ ├── r │ │ ├── index.jsx │ │ ├── index2.jsx │ │ └── App.jsx │ ├── tsconfig.build.json │ ├── mock │ │ └── test.ts │ ├── index.pug │ └── index.css ├── vite4-demo │ ├── src │ │ ├── custom-modules.d.ts │ │ ├── util │ │ │ ├── typings.ts │ │ │ ├── normalize.js │ │ │ ├── noop.ts │ │ │ ├── isDate.ts │ │ │ ├── outputFileSync.js │ │ │ ├── isNil.ts │ │ │ ├── isError.ts │ │ │ ├── outputFile.js │ │ │ ├── isNumber.ts │ │ │ └── isAsyncFunction.ts │ │ └── separate-importer.jsx │ ├── v │ │ ├── main.ts │ │ └── App.vue │ ├── r │ │ ├── index.jsx │ │ ├── index2.jsx │ │ └── App.jsx │ ├── tsconfig.build.json │ ├── mock │ │ └── test.ts │ ├── index.pug │ └── index.css ├── vite5-demo │ ├── src │ │ ├── custom-modules.d.ts │ │ ├── util │ │ │ ├── typings.ts │ │ │ ├── normalize.js │ │ │ ├── noop.ts │ │ │ ├── isDate.ts │ │ │ ├── outputFileSync.js │ │ │ ├── isNil.ts │ │ │ ├── isError.ts │ │ │ ├── outputFile.js │ │ │ ├── isNumber.ts │ │ │ └── isAsyncFunction.ts │ │ └── separate-importer.jsx │ ├── v │ │ ├── main.ts │ │ └── App.vue │ ├── tsconfig.build.json │ ├── r │ │ ├── index.jsx │ │ └── index2.jsx │ ├── mock │ │ └── test.ts │ ├── index.pug │ └── index.css ├── vite6-view │ ├── v │ │ ├── main.ts │ │ └── App.vue │ ├── tsconfig.build.json │ ├── index.pug │ ├── package.json │ └── index.css ├── vite3-view │ ├── tsconfig.build.json │ ├── r │ │ └── index.jsx │ ├── package.json │ ├── index.njk │ └── index.css ├── vite4-view │ ├── tsconfig.build.json │ ├── r │ │ └── index.jsx │ ├── package.json │ ├── index.hbs │ └── index.css ├── vite5-view │ ├── tsconfig.build.json │ ├── r │ │ └── index.jsx │ ├── package.json │ ├── index.ejs │ └── index.css └── config │ ├── vite.hook-use.1.mts │ ├── vite.external.9.mts │ ├── vite.combine.1.mts │ ├── vite.combine.3.mts │ ├── vite.combine.6.mts │ ├── vite.combine.2.mts │ ├── vite.combine.4.mts │ ├── vite.combine.5.mts │ ├── vite.view.6.mts │ ├── vite.external.11.mts │ ├── vite.view.5.mts │ ├── vite.external.5.mts │ ├── vite.external.6.mts │ ├── vite.include-css.1.mts │ ├── vite.mock-data.1.mts │ ├── vite.view.4.mts │ ├── vite.external.2.mts │ ├── vite.external.1.mts │ ├── vite.external.8.mts │ ├── vite.reverse-proxy.1.mts │ ├── vite.external.7.mts │ ├── vite.external.4.mts │ ├── vite.external.3.mts │ ├── vite.view.3.mts │ ├── vite.external.10.mts │ ├── vite.separate-importer.1.mts │ └── vite.mock-data.2.mts ├── .lintstagedrc ├── docs ├── zh │ ├── guide │ │ ├── contribution.md │ │ ├── introduction.md │ │ └── local-debugging.md │ ├── index.md │ └── plugins │ │ ├── vite-plugin-mock-data │ │ └── quick-start.md │ │ ├── vite-plugin-hook-use │ │ ├── usage.md │ │ └── quick-start.md │ │ ├── vite-plugin-separate-importer │ │ ├── quick-start.md │ │ └── options.md │ │ ├── vite-plugin-combine │ │ ├── usage.md │ │ └── quick-start.md │ │ └── vite-plugin-include-css │ │ └── quick-start.md ├── .vitepress │ ├── config │ │ └── index.mts │ └── theme │ │ └── index.ts └── en │ ├── guide │ ├── contribution.md │ └── introduction.md │ ├── index.md │ └── plugins │ ├── vite-plugin-mock-data │ └── quick-start.md │ ├── vite-plugin-separate-importer │ ├── quick-start.md │ └── options.md │ ├── vite-plugin-hook-use │ ├── quick-start.md │ └── usage.md │ ├── vite-plugin-combine │ └── usage.md │ └── vite-plugin-include-css │ └── quick-start.md ├── .eslintrc ├── tsconfig.json ├── tsconfig.base.json ├── LICENSE └── .github └── workflows └── npm-publish.yml /.husky/_/.gitignore: -------------------------------------------------------------------------------- 1 | * -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | lockfile=false 2 | shamefully-hoist=true -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/.npmignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - 'packages/*' 3 | - 'examples/*' -------------------------------------------------------------------------------- /packages/cs-runtime-helper/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './generateStarter'; 2 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/_husky/pre-commit: -------------------------------------------------------------------------------- 1 | npx --no-install -- lint-staged -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/_npmrc: -------------------------------------------------------------------------------- 1 | lockfile=false 2 | shamefully-hoist=true -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { extends: ['@commitlint/config-conventional'] }; 2 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/_husky/commit-msg: -------------------------------------------------------------------------------- 1 | npx --no-install -- commitlint --edit $1 -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/docs/en/guide/introduction.md: -------------------------------------------------------------------------------- 1 | # create-vite-lib-starter 2 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/docs/zh/guide/introduction.md: -------------------------------------------------------------------------------- 1 | # create-vite-lib-starter 2 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | *.sh 2 | node_modules 3 | logs 4 | dist 5 | gh-pages 6 | coverage 7 | LICENSE 8 | README.md -------------------------------------------------------------------------------- /examples/vite6-demo/custom-modules.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'antd' { 2 | export const Button: any; 3 | } 4 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/docs/.vitepress/cache/deps/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module" 3 | } 4 | -------------------------------------------------------------------------------- /examples/vite3-demo/src/custom-modules.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'antd' { 2 | export const Button: any; 3 | } 4 | -------------------------------------------------------------------------------- /examples/vite4-demo/src/custom-modules.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'antd' { 2 | export const Button: any; 3 | } 4 | -------------------------------------------------------------------------------- /examples/vite5-demo/src/custom-modules.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'antd' { 2 | export const Button: any; 3 | } 4 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | . "$(dirname -- "$0")/_/husky.sh" 3 | 4 | npx --no-install -- lint-staged 5 | -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | . "$(dirname -- "$0")/_/husky.sh" 3 | 4 | npx --no-install -- commitlint --edit $1 5 | -------------------------------------------------------------------------------- /examples/vite3-demo/src/util/typings.ts: -------------------------------------------------------------------------------- 1 | export interface Options { 2 | src: string | string[]; 3 | 4 | target: string; 5 | } 6 | -------------------------------------------------------------------------------- /examples/vite4-demo/src/util/typings.ts: -------------------------------------------------------------------------------- 1 | export interface Options { 2 | src: string | string[]; 3 | 4 | target: string; 5 | } 6 | -------------------------------------------------------------------------------- /examples/vite5-demo/src/util/typings.ts: -------------------------------------------------------------------------------- 1 | export interface Options { 2 | src: string | string[]; 3 | 4 | target: string; 5 | } 6 | -------------------------------------------------------------------------------- /examples/vite6-demo/src/util/typings.ts: -------------------------------------------------------------------------------- 1 | export interface Options { 2 | src: string | string[]; 3 | 4 | target: string; 5 | } 6 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/_eslintignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea 3 | .vscode 4 | 5 | dist 6 | logs 7 | coverage 8 | node_modules -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/commitlint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['@commitlint/config-conventional'] 3 | }; 4 | -------------------------------------------------------------------------------- /.lintstagedrc: -------------------------------------------------------------------------------- 1 | { 2 | "*.ts?(x)": "eslint --fix --ignore-path .eslintignore", 3 | "*.js?(x)": "eslint --fix --ignore-path .eslintignore" 4 | } -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/src/index.ts: -------------------------------------------------------------------------------- 1 | export { default as isNil } from './isNil'; 2 | export { default as noop } from './noop'; 3 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/tsconfig.typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "include": [ 4 | "src" 5 | ] 6 | } -------------------------------------------------------------------------------- /examples/vite6-view/v/main.ts: -------------------------------------------------------------------------------- 1 | import { createApp } from 'vue'; 2 | 3 | import App from './App.vue'; 4 | 5 | createApp(App).mount('#root'); 6 | -------------------------------------------------------------------------------- /examples/vite3-demo/src/util/normalize.js: -------------------------------------------------------------------------------- 1 | import { normalizePath } from 'vite'; 2 | 3 | export default function normalize(str) { 4 | return normalizePath(str); 5 | } 6 | -------------------------------------------------------------------------------- /examples/vite4-demo/src/util/normalize.js: -------------------------------------------------------------------------------- 1 | import { normalizePath } from 'vite'; 2 | 3 | export default function normalize(str) { 4 | return normalizePath(str); 5 | } 6 | -------------------------------------------------------------------------------- /examples/vite5-demo/src/util/normalize.js: -------------------------------------------------------------------------------- 1 | import { normalizePath } from 'vite'; 2 | 3 | export default function normalize(str) { 4 | return normalizePath(str); 5 | } 6 | -------------------------------------------------------------------------------- /examples/vite6-demo/src/util/normalize.js: -------------------------------------------------------------------------------- 1 | import { normalizePath } from 'vite'; 2 | 3 | export default function normalize(str) { 4 | return normalizePath(str); 5 | } 6 | -------------------------------------------------------------------------------- /examples/vite3-demo/v/main.ts: -------------------------------------------------------------------------------- 1 | import '../index.css'; 2 | 3 | import { createApp } from 'vue'; 4 | 5 | import App from './App.vue'; 6 | 7 | createApp(App).mount('#root'); 8 | -------------------------------------------------------------------------------- /examples/vite4-demo/v/main.ts: -------------------------------------------------------------------------------- 1 | import '../index.css'; 2 | 3 | import { createApp } from 'vue'; 4 | 5 | import App from './App.vue'; 6 | 7 | createApp(App).mount('#root'); 8 | -------------------------------------------------------------------------------- /examples/vite5-demo/v/main.ts: -------------------------------------------------------------------------------- 1 | import '../index.css'; 2 | 3 | import { createApp } from 'vue'; 4 | 5 | import App from './App.vue'; 6 | 7 | createApp(App).mount('#root'); 8 | -------------------------------------------------------------------------------- /examples/vite6-demo/v/main.ts: -------------------------------------------------------------------------------- 1 | import '../index.css'; 2 | 3 | import { createApp } from 'vue'; 4 | 5 | import App from './App.vue'; 6 | 7 | createApp(App).mount('#root'); 8 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/_lintstagedrc: -------------------------------------------------------------------------------- 1 | { 2 | "*.ts?(x)": "eslint --fix --ignore-path .eslintignore", 3 | "*.js?(x)": "eslint --fix --ignore-path .eslintignore" 4 | } -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/docs/.vitepress/cache/deps/vue.js.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "sources": [], 4 | "sourcesContent": [], 5 | "mappings": "", 6 | "names": [] 7 | } 8 | -------------------------------------------------------------------------------- /docs/zh/guide/contribution.md: -------------------------------------------------------------------------------- 1 | # 贡献指南 2 | 3 | 我们欢迎社区的贡献!如果您发现 Bug 或希望提出改进建议,请随时提交 Issue 或 Pull Request。 4 | 5 | ## 如何贡献 6 | 1. Fork 仓库。 7 | 2. 为您的更改创建新分支。 8 | 3. 提交 Pull Request,并附上对更改的清晰描述。 9 | -------------------------------------------------------------------------------- /examples/vite3-demo/src/separate-importer.jsx: -------------------------------------------------------------------------------- 1 | import { Button } from 'antd'; 2 | import React from 'react'; 3 | 4 | export function WrappedButton() { 5 | return ; 6 | } 7 | -------------------------------------------------------------------------------- /examples/vite4-demo/src/separate-importer.jsx: -------------------------------------------------------------------------------- 1 | import { Button } from 'antd'; 2 | import React from 'react'; 3 | 4 | export function WrappedButton() { 5 | return ; 6 | } 7 | -------------------------------------------------------------------------------- /examples/vite5-demo/src/separate-importer.jsx: -------------------------------------------------------------------------------- 1 | import { Button } from 'antd'; 2 | import React from 'react'; 3 | 4 | export function WrappedButton() { 5 | return ; 6 | } 7 | -------------------------------------------------------------------------------- /examples/vite6-demo/src/separate-importer.jsx: -------------------------------------------------------------------------------- 1 | import { Button } from 'antd'; 2 | import React from 'react'; 3 | 4 | export function WrappedButton() { 5 | return ; 6 | } 7 | -------------------------------------------------------------------------------- /packages/vite-plugin-external/src/common/constants.ts: -------------------------------------------------------------------------------- 1 | import { name } from '../../package.json'; 2 | 3 | export const PLUGIN_NAME = name; 4 | export const ESBUILD_PLUGIN_NAME = 'esbuild-plugin-resolve'; 5 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/src/noop.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Empty function that does nothing. 3 | */ 4 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 5 | export default function noop(...args: any[]) {} 6 | -------------------------------------------------------------------------------- /packages/vite-plugin-external/src/common/logger.ts: -------------------------------------------------------------------------------- 1 | import { logFactory } from 'vp-runtime-helper'; 2 | 3 | import { PLUGIN_NAME } from './constants'; 4 | 5 | export const logger = logFactory.getLogger(PLUGIN_NAME); 6 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/docs/zh/api/entry.md: -------------------------------------------------------------------------------- 1 | **create-vite-lib-starter** 2 | 3 | *** 4 | 5 | # create-vite-lib-starter 6 | 7 | ## 模块 8 | 9 | - [index](index.md) 10 | - [isNil](isNil.md) 11 | - [noop](noop.md) 12 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/docs/en/api/entry.md: -------------------------------------------------------------------------------- 1 | **create-vite-lib-starter** 2 | 3 | *** 4 | 5 | # create-vite-lib-starter 6 | 7 | ## Modules 8 | 9 | - [index](index.md) 10 | - [isNil](isNil.md) 11 | - [noop](noop.md) 12 | -------------------------------------------------------------------------------- /packages/vite-plugin-view/src/logger.ts: -------------------------------------------------------------------------------- 1 | import { logFactory } from 'vp-runtime-helper'; 2 | 3 | import { name } from '../package.json'; 4 | 5 | export const PLUGIN_NAME = name; 6 | 7 | export const logger = logFactory.getLogger(PLUGIN_NAME); 8 | -------------------------------------------------------------------------------- /packages/vite-plugin-combine/src/logger.ts: -------------------------------------------------------------------------------- 1 | import { logFactory } from 'vp-runtime-helper'; 2 | 3 | import { name } from '../package.json'; 4 | 5 | export const PLUGIN_NAME = name; 6 | 7 | export const logger = logFactory.getLogger(PLUGIN_NAME); 8 | -------------------------------------------------------------------------------- /packages/vite-plugin-cp/src/logger.ts: -------------------------------------------------------------------------------- 1 | 2 | import { logFactory } from 'vp-runtime-helper'; 3 | 4 | import { name } from '../package.json'; 5 | 6 | export const PLUGIN_NAME = name; 7 | 8 | export const logger = logFactory.getLogger(PLUGIN_NAME); 9 | -------------------------------------------------------------------------------- /packages/vite-plugin-mock-data/src/logger.ts: -------------------------------------------------------------------------------- 1 | import { logFactory } from 'vp-runtime-helper'; 2 | 3 | import { name } from '../package.json'; 4 | 5 | export const PLUGIN_NAME = name; 6 | 7 | export const logger = logFactory.getLogger(PLUGIN_NAME); 8 | -------------------------------------------------------------------------------- /packages/vite-plugin-separate-importer/src/logger.ts: -------------------------------------------------------------------------------- 1 | import { logFactory } from 'vp-runtime-helper'; 2 | 3 | import { name } from '../package.json'; 4 | 5 | export const PLUGIN_NAME = name; 6 | 7 | export const logger = logFactory.getLogger(PLUGIN_NAME); 8 | -------------------------------------------------------------------------------- /examples/vite3-demo/r/index.jsx: -------------------------------------------------------------------------------- 1 | import '../index.css'; 2 | 3 | import React from 'react'; 4 | import ReactDOM from 'react-dom'; 5 | 6 | import App from './App'; 7 | 8 | ReactDOM.render( 9 | , 10 | document.getElementById('root') 11 | ); 12 | -------------------------------------------------------------------------------- /examples/vite4-demo/r/index.jsx: -------------------------------------------------------------------------------- 1 | import '../index.css'; 2 | 3 | import React from 'react'; 4 | import ReactDOM from 'react-dom'; 5 | 6 | import App from './App'; 7 | 8 | ReactDOM.render( 9 | , 10 | document.getElementById('root') 11 | ); 12 | -------------------------------------------------------------------------------- /examples/vite6-demo/r/index.jsx: -------------------------------------------------------------------------------- 1 | import '../index.css'; 2 | 3 | import React from 'react'; 4 | import ReactDOM from 'react-dom'; 5 | 6 | import App from './App'; 7 | 8 | ReactDOM.render( 9 | , 10 | document.getElementById('root') 11 | ); 12 | -------------------------------------------------------------------------------- /examples/vite6-view/v/App.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | -------------------------------------------------------------------------------- /examples/vite3-demo/src/util/noop.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 空函数 4 | * 5 | * @example 6 | * ```js 7 | * noop(); 8 | * noop(1, 2, 3); 9 | * noop.call(null); 10 | * ``` 11 | * 12 | * @param args 任意参数 13 | */ 14 | function noop(...args: any[]): any; 15 | function noop(): any {} 16 | export default noop; 17 | -------------------------------------------------------------------------------- /examples/vite4-demo/src/util/noop.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 空函数 4 | * 5 | * @example 6 | * ```js 7 | * noop(); 8 | * noop(1, 2, 3); 9 | * noop.call(null); 10 | * ``` 11 | * 12 | * @param args 任意参数 13 | */ 14 | function noop(...args: any[]): any; 15 | function noop(): any {} 16 | export default noop; 17 | -------------------------------------------------------------------------------- /examples/vite5-demo/src/util/noop.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 空函数 4 | * 5 | * @example 6 | * ```js 7 | * noop(); 8 | * noop(1, 2, 3); 9 | * noop.call(null); 10 | * ``` 11 | * 12 | * @param args 任意参数 13 | */ 14 | function noop(...args: any[]): any; 15 | function noop(): any {} 16 | export default noop; 17 | -------------------------------------------------------------------------------- /examples/vite6-demo/src/util/noop.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 空函数 4 | * 5 | * @example 6 | * ```js 7 | * noop(); 8 | * noop(1, 2, 3); 9 | * noop.call(null); 10 | * ``` 11 | * 12 | * @param args 任意参数 13 | */ 14 | function noop(...args: any[]): any; 15 | function noop(): any {} 16 | export default noop; 17 | -------------------------------------------------------------------------------- /examples/vite3-demo/r/index2.jsx: -------------------------------------------------------------------------------- 1 | import '../index.css'; 2 | 3 | import { StrictMode } from 'react'; 4 | import { createRoot } from 'react-dom/client'; 5 | 6 | import App from './App'; 7 | 8 | createRoot(document.getElementById('root')).render( 9 | 10 | 11 | , 12 | ); 13 | -------------------------------------------------------------------------------- /examples/vite4-demo/r/index2.jsx: -------------------------------------------------------------------------------- 1 | import '../index.css'; 2 | 3 | import { StrictMode } from 'react'; 4 | import { createRoot } from 'react-dom/client'; 5 | 6 | import App from './App'; 7 | 8 | createRoot(document.getElementById('root')).render( 9 | 10 | 11 | , 12 | ); 13 | -------------------------------------------------------------------------------- /examples/vite6-demo/r/index2.jsx: -------------------------------------------------------------------------------- 1 | import '../index.css'; 2 | 3 | import { StrictMode } from 'react'; 4 | import { createRoot } from 'react-dom/client'; 5 | 6 | import App from './App'; 7 | 8 | createRoot(document.getElementById('root')).render( 9 | 10 | 11 | , 12 | ); 13 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "include": [ 4 | "./src/**/*.ts", 5 | "./test/*.ts", 6 | "./docs/.vitepress/**/*.ts", 7 | "./docs/.vitepress/**/*.mts", 8 | "./node_modules/vite/client.d.ts", 9 | "./vite.config.mts" 10 | ] 11 | } -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "fe", 4 | "fe/ts", 5 | "fe/react" 6 | ], 7 | "plugins": [ 8 | "simple-import-sort" 9 | ], 10 | "globals": { 11 | "__DEV__": true 12 | }, 13 | "rules": { 14 | "simple-import-sort/imports": "error", 15 | "simple-import-sort/exports": "error" 16 | } 17 | } -------------------------------------------------------------------------------- /examples/vite3-demo/v/App.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | -------------------------------------------------------------------------------- /examples/vite4-demo/v/App.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | -------------------------------------------------------------------------------- /examples/vite5-demo/v/App.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | -------------------------------------------------------------------------------- /examples/vite6-demo/v/App.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "emitDeclarationOnly": true, 6 | "declarationDir": "dist" 7 | }, 8 | "include": [ 9 | "./src/**/*.ts", 10 | "./node_modules/vite/client.d.ts" 11 | ] 12 | } -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/_eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "fe", 4 | "fe/ts" 5 | ], 6 | "plugins": [ 7 | "simple-import-sort" 8 | ], 9 | "globals": { 10 | "__DEV__": true 11 | }, 12 | "rules": { 13 | "simple-import-sort/imports": "error", 14 | "simple-import-sort/exports": "error" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/docs/zh/api/index.md: -------------------------------------------------------------------------------- 1 | [**create-vite-lib-starter**](entry.md) 2 | 3 | *** 4 | 5 | [create-vite-lib-starter](entry.md) / index 6 | 7 | # index 8 | 9 | ## 参考 10 | 11 | ### isNil 12 | 13 | 重命名并重新导出 [default](isNil.md#default) 14 | 15 | *** 16 | 17 | ### noop 18 | 19 | 重命名并重新导出 [default](noop.md#default) 20 | -------------------------------------------------------------------------------- /docs/.vitepress/config/index.mts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vitepress' 2 | import { shared } from './shared.mts' 3 | import { en } from './en.mts' 4 | import { zh } from './zh.mts' 5 | 6 | export default defineConfig({ 7 | ...shared, 8 | locales: { 9 | root: { label: 'English', ...en }, 10 | zh: { label: '简体中文', ...zh }, 11 | } 12 | }) -------------------------------------------------------------------------------- /examples/vite3-demo/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "emitDeclarationOnly": true, 6 | "declarationDir": "dist" 7 | }, 8 | "include": [ 9 | "src", 10 | "./node_modules/vite/client.d.ts" 11 | ], 12 | "exclude": [ 13 | "dist" 14 | ] 15 | } -------------------------------------------------------------------------------- /examples/vite3-view/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "emitDeclarationOnly": true, 6 | "declarationDir": "dist" 7 | }, 8 | "include": [ 9 | "src", 10 | "./node_modules/vite/client.d.ts" 11 | ], 12 | "exclude": [ 13 | "dist" 14 | ] 15 | } -------------------------------------------------------------------------------- /examples/vite4-demo/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "emitDeclarationOnly": true, 6 | "declarationDir": "dist" 7 | }, 8 | "include": [ 9 | "src", 10 | "./node_modules/vite/client.d.ts" 11 | ], 12 | "exclude": [ 13 | "dist" 14 | ] 15 | } -------------------------------------------------------------------------------- /examples/vite4-view/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "emitDeclarationOnly": true, 6 | "declarationDir": "dist" 7 | }, 8 | "include": [ 9 | "src", 10 | "./node_modules/vite/client.d.ts" 11 | ], 12 | "exclude": [ 13 | "dist" 14 | ] 15 | } -------------------------------------------------------------------------------- /examples/vite5-demo/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "emitDeclarationOnly": true, 6 | "declarationDir": "dist" 7 | }, 8 | "include": [ 9 | "src", 10 | "./node_modules/vite/client.d.ts" 11 | ], 12 | "exclude": [ 13 | "dist" 14 | ] 15 | } -------------------------------------------------------------------------------- /examples/vite5-view/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "emitDeclarationOnly": true, 6 | "declarationDir": "dist" 7 | }, 8 | "include": [ 9 | "src", 10 | "./node_modules/vite/client.d.ts" 11 | ], 12 | "exclude": [ 13 | "dist" 14 | ] 15 | } -------------------------------------------------------------------------------- /examples/vite6-demo/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "emitDeclarationOnly": true, 6 | "declarationDir": "dist" 7 | }, 8 | "include": [ 9 | "src", 10 | "./node_modules/vite/client.d.ts" 11 | ], 12 | "exclude": [ 13 | "dist" 14 | ] 15 | } -------------------------------------------------------------------------------- /examples/vite6-view/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "emitDeclarationOnly": true, 6 | "declarationDir": "dist" 7 | }, 8 | "include": [ 9 | "src", 10 | "./node_modules/vite/client.d.ts" 11 | ], 12 | "exclude": [ 13 | "dist" 14 | ] 15 | } -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/docs/zh/api/noop.md: -------------------------------------------------------------------------------- 1 | [**create-vite-lib-starter**](entry.md) 2 | 3 | *** 4 | 5 | [create-vite-lib-starter](entry.md) / noop 6 | 7 | # noop 8 | 9 | ## 函数 10 | 11 | ### default() 12 | 13 | > **default**(): `void` 14 | 15 | 定义于: noop.ts:4 16 | 17 | Empty function that does nothing. 18 | 19 | #### 返回 20 | 21 | `void` 22 | -------------------------------------------------------------------------------- /packages/vite-plugin-cp/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "emitDeclarationOnly": true, 6 | "declarationDir": "dist" 7 | }, 8 | "include": [ 9 | "src", 10 | "./node_modules/vite/client.d.ts" 11 | ], 12 | "exclude": [ 13 | "dist" 14 | ] 15 | } -------------------------------------------------------------------------------- /packages/cs-runtime-helper/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "emitDeclarationOnly": true, 6 | "declarationDir": "dist" 7 | }, 8 | "include": [ 9 | "src", 10 | "./node_modules/vite/client.d.ts" 11 | ], 12 | "exclude": [ 13 | "dist" 14 | ] 15 | } -------------------------------------------------------------------------------- /packages/vite-plugin-external/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "emitDeclarationOnly": true, 6 | "declarationDir": "dist" 7 | }, 8 | "include": [ 9 | "src", 10 | "./node_modules/vite/client.d.ts" 11 | ], 12 | "exclude": [ 13 | "dist" 14 | ] 15 | } -------------------------------------------------------------------------------- /packages/vite-plugin-hook-use/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "emitDeclarationOnly": true, 6 | "declarationDir": "dist" 7 | }, 8 | "include": [ 9 | "src", 10 | "./node_modules/vite/client.d.ts" 11 | ], 12 | "exclude": [ 13 | "dist" 14 | ] 15 | } -------------------------------------------------------------------------------- /packages/vite-plugin-view/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "emitDeclarationOnly": true, 6 | "declarationDir": "dist" 7 | }, 8 | "include": [ 9 | "src", 10 | "./node_modules/vite/client.d.ts" 11 | ], 12 | "exclude": [ 13 | "dist" 14 | ] 15 | } -------------------------------------------------------------------------------- /packages/vp-runtime-helper/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "emitDeclarationOnly": true, 6 | "declarationDir": "dist" 7 | }, 8 | "include": [ 9 | "src", 10 | "./node_modules/vite/client.d.ts" 11 | ], 12 | "exclude": [ 13 | "dist" 14 | ] 15 | } -------------------------------------------------------------------------------- /docs/en/guide/contribution.md: -------------------------------------------------------------------------------- 1 | # Contribution 2 | 3 | We welcome contributions from the community! If you find a bug or want to suggest an improvement, feel free to open an issue or submit a pull request. 4 | 5 | ## How to Contribute 6 | 1. Fork the repository. 7 | 2. Create a new branch for your changes. 8 | 3. Submit a pull request with a clear description of your changes. 9 | -------------------------------------------------------------------------------- /packages/vite-plugin-build-chunk/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "emitDeclarationOnly": true, 6 | "declarationDir": "dist" 7 | }, 8 | "include": [ 9 | "src", 10 | "./node_modules/vite/client.d.ts" 11 | ], 12 | "exclude": [ 13 | "dist" 14 | ] 15 | } -------------------------------------------------------------------------------- /packages/vite-plugin-include-css/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "emitDeclarationOnly": true, 6 | "declarationDir": "dist" 7 | }, 8 | "include": [ 9 | "src", 10 | "./node_modules/vite/client.d.ts" 11 | ], 12 | "exclude": [ 13 | "dist" 14 | ] 15 | } -------------------------------------------------------------------------------- /packages/vite-plugin-mock-data/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "emitDeclarationOnly": true, 6 | "declarationDir": "dist" 7 | }, 8 | "include": [ 9 | "src", 10 | "./node_modules/vite/client.d.ts" 11 | ], 12 | "exclude": [ 13 | "dist" 14 | ] 15 | } -------------------------------------------------------------------------------- /packages/vite-plugin-reverse-proxy/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "emitDeclarationOnly": true, 6 | "declarationDir": "dist" 7 | }, 8 | "include": [ 9 | "src", 10 | "./node_modules/vite/client.d.ts" 11 | ], 12 | "exclude": [ 13 | "dist" 14 | ] 15 | } -------------------------------------------------------------------------------- /packages/vite-plugin-combine/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "emitDeclarationOnly": true, 6 | "declarationDir": "dist" 7 | }, 8 | "include": [ 9 | "src/**/*.ts", 10 | "./node_modules/vite/client.d.ts" 11 | ], 12 | "exclude": [ 13 | "dist" 14 | ] 15 | } -------------------------------------------------------------------------------- /packages/vite-plugin-separate-importer/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "emitDeclarationOnly": true, 6 | "declarationDir": "dist" 7 | }, 8 | "include": [ 9 | "src", 10 | "./node_modules/vite/client.d.ts" 11 | ], 12 | "exclude": [ 13 | "dist" 14 | ] 15 | } -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/docs/en/api/index.md: -------------------------------------------------------------------------------- 1 | [**create-vite-lib-starter**](entry.md) 2 | 3 | *** 4 | 5 | [create-vite-lib-starter](entry.md) / index 6 | 7 | # index 8 | 9 | ## References 10 | 11 | ### isNil 12 | 13 | Renames and re-exports [default](isNil.md#default) 14 | 15 | *** 16 | 17 | ### noop 18 | 19 | Renames and re-exports [default](noop.md#default) 20 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/docs/en/api/noop.md: -------------------------------------------------------------------------------- 1 | [**create-vite-lib-starter**](entry.md) 2 | 3 | *** 4 | 5 | [create-vite-lib-starter](entry.md) / noop 6 | 7 | # noop 8 | 9 | ## Functions 10 | 11 | ### default() 12 | 13 | > **default**(): `void` 14 | 15 | Defined in: noop.ts:4 16 | 17 | Empty function that does nothing. 18 | 19 | #### Returns 20 | 21 | `void` 22 | -------------------------------------------------------------------------------- /examples/vite3-demo/src/util/isDate.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 检查是否是日期对象 4 | * 5 | * @example 6 | * ```js 7 | * isDate(new Date()); //true 8 | * isDate({}); //false 9 | * ``` 10 | * 11 | * @param value 要检查的值 12 | * @returns 如果是日期对象则返回 `true`,否则返回 `false` 13 | */ 14 | export default function isDate(value: any): value is Date { 15 | return value instanceof Date; 16 | } 17 | -------------------------------------------------------------------------------- /examples/vite4-demo/src/util/isDate.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 检查是否是日期对象 4 | * 5 | * @example 6 | * ```js 7 | * isDate(new Date()); //true 8 | * isDate({}); //false 9 | * ``` 10 | * 11 | * @param value 要检查的值 12 | * @returns 如果是日期对象则返回 `true`,否则返回 `false` 13 | */ 14 | export default function isDate(value: any): value is Date { 15 | return value instanceof Date; 16 | } 17 | -------------------------------------------------------------------------------- /examples/vite5-demo/src/util/isDate.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 检查是否是日期对象 4 | * 5 | * @example 6 | * ```js 7 | * isDate(new Date()); //true 8 | * isDate({}); //false 9 | * ``` 10 | * 11 | * @param value 要检查的值 12 | * @returns 如果是日期对象则返回 `true`,否则返回 `false` 13 | */ 14 | export default function isDate(value: any): value is Date { 15 | return value instanceof Date; 16 | } 17 | -------------------------------------------------------------------------------- /examples/vite6-demo/src/util/isDate.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 检查是否是日期对象 4 | * 5 | * @example 6 | * ```js 7 | * isDate(new Date()); //true 8 | * isDate({}); //false 9 | * ``` 10 | * 11 | * @param value 要检查的值 12 | * @returns 如果是日期对象则返回 `true`,否则返回 `false` 13 | */ 14 | export default function isDate(value: any): value is Date { 15 | return value instanceof Date; 16 | } 17 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/docs/.vitepress/config/index.mts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vitepress' 2 | import { shared } from './shared.mts' 3 | import { en } from './en.mts' 4 | import { zh } from './zh.mts' 5 | 6 | export default defineConfig({ 7 | ...shared, 8 | locales: { 9 | root: { label: 'English', ...en }, 10 | zh: { label: '简体中文', ...zh }, 11 | } 12 | }) -------------------------------------------------------------------------------- /examples/vite3-demo/r/App.jsx: -------------------------------------------------------------------------------- 1 | import React, { useState, version } from 'react'; 2 | 3 | export default function App() { 4 | const [count, setCount] = useState(0); 5 | return ( 6 |
7 |

{version}

8 |

Count: {count}

9 | 10 |
11 | ); 12 | } 13 | -------------------------------------------------------------------------------- /examples/vite4-demo/r/App.jsx: -------------------------------------------------------------------------------- 1 | import React, { useState, version } from 'react'; 2 | 3 | export default function App() { 4 | const [count, setCount] = useState(0); 5 | return ( 6 |
7 |

{version}

8 |

Count: {count}

9 | 10 |
11 | ); 12 | } 13 | -------------------------------------------------------------------------------- /examples/vite6-demo/r/App.jsx: -------------------------------------------------------------------------------- 1 | import React, { useState, version } from 'react'; 2 | 3 | export default function App() { 4 | const [count, setCount] = useState(0); 5 | return ( 6 |
7 |

{version}

8 |

Count: {count}

9 | 10 |
11 | ); 12 | } 13 | -------------------------------------------------------------------------------- /packages/vp-runtime-helper/src/colorful.ts: -------------------------------------------------------------------------------- 1 | import picocolors from 'picocolors'; 2 | 3 | export const colorful = {} as Record, (...args: any[]) => void>; 4 | Object.entries(picocolors).forEach(([key, value]) => { 5 | colorful[key] = (text: string) => { 6 | // eslint-disable-next-line no-console 7 | console.log(value(text)); 8 | }; 9 | }); 10 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "include": [ 4 | "./node_modules/vite/client.d.ts", 5 | "./docs/.vitepress/**/*.ts", 6 | "./docs/.vitepress/**/*.mts", 7 | "./packages/**/*.ts", 8 | "./packages/**/*.mts", 9 | "./examples/**/*.ts", 10 | "./examples/**/*.mts", 11 | ], 12 | "exclude": [ 13 | "dist", 14 | "node_modules" 15 | ] 16 | } -------------------------------------------------------------------------------- /examples/vite3-demo/src/util/outputFileSync.js: -------------------------------------------------------------------------------- 1 | import { existsSync, mkdirSync, writeFileSync } from 'node:fs'; 2 | import { dirname } from 'node:path'; 3 | 4 | export function outputFileSync(file, data, options = 'utf-8') { 5 | const dir = dirname(file); 6 | 7 | if (!existsSync(dir)) { 8 | mkdirSync(dir, { recursive: true }); 9 | } 10 | 11 | return writeFileSync(file, data, options); 12 | } 13 | -------------------------------------------------------------------------------- /examples/vite4-demo/src/util/outputFileSync.js: -------------------------------------------------------------------------------- 1 | import { existsSync, mkdirSync, writeFileSync } from 'node:fs'; 2 | import { dirname } from 'node:path'; 3 | 4 | export function outputFileSync(file, data, options = 'utf-8') { 5 | const dir = dirname(file); 6 | 7 | if (!existsSync(dir)) { 8 | mkdirSync(dir, { recursive: true }); 9 | } 10 | 11 | return writeFileSync(file, data, options); 12 | } 13 | -------------------------------------------------------------------------------- /examples/vite5-demo/src/util/outputFileSync.js: -------------------------------------------------------------------------------- 1 | import { existsSync, mkdirSync, writeFileSync } from 'node:fs'; 2 | import { dirname } from 'node:path'; 3 | 4 | export function outputFileSync(file, data, options = 'utf-8') { 5 | const dir = dirname(file); 6 | 7 | if (!existsSync(dir)) { 8 | mkdirSync(dir, { recursive: true }); 9 | } 10 | 11 | return writeFileSync(file, data, options); 12 | } 13 | -------------------------------------------------------------------------------- /examples/vite6-demo/src/util/outputFileSync.js: -------------------------------------------------------------------------------- 1 | import { existsSync, mkdirSync, writeFileSync } from 'node:fs'; 2 | import { dirname } from 'node:path'; 3 | 4 | export function outputFileSync(file, data, options = 'utf-8') { 5 | const dir = dirname(file); 6 | 7 | if (!existsSync(dir)) { 8 | mkdirSync(dir, { recursive: true }); 9 | } 10 | 11 | return writeFileSync(file, data, options); 12 | } 13 | -------------------------------------------------------------------------------- /examples/vite3-demo/src/util/isNil.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 检查是否是 null 或 undefined 4 | * 5 | * @example 6 | * ```js 7 | * isNil(null); // true 8 | * isNil(undefined); // true 9 | * isNil({}); // false 10 | * ``` 11 | * 12 | * @param value 要检查的值 13 | * @returns 是 null 或 undefined 返回 true,否则返回 false 14 | */ 15 | export default function isNil(value: T): boolean { 16 | return value == null; 17 | } 18 | -------------------------------------------------------------------------------- /examples/vite4-demo/src/util/isNil.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 检查是否是 null 或 undefined 4 | * 5 | * @example 6 | * ```js 7 | * isNil(null); // true 8 | * isNil(undefined); // true 9 | * isNil({}); // false 10 | * ``` 11 | * 12 | * @param value 要检查的值 13 | * @returns 是 null 或 undefined 返回 true,否则返回 false 14 | */ 15 | export default function isNil(value: T): boolean { 16 | return value == null; 17 | } 18 | -------------------------------------------------------------------------------- /examples/vite5-demo/src/util/isNil.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 检查是否是 null 或 undefined 4 | * 5 | * @example 6 | * ```js 7 | * isNil(null); // true 8 | * isNil(undefined); // true 9 | * isNil({}); // false 10 | * ``` 11 | * 12 | * @param value 要检查的值 13 | * @returns 是 null 或 undefined 返回 true,否则返回 false 14 | */ 15 | export default function isNil(value: T): boolean { 16 | return value == null; 17 | } 18 | -------------------------------------------------------------------------------- /examples/vite6-demo/src/util/isNil.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 检查是否是 null 或 undefined 4 | * 5 | * @example 6 | * ```js 7 | * isNil(null); // true 8 | * isNil(undefined); // true 9 | * isNil({}); // false 10 | * ``` 11 | * 12 | * @param value 要检查的值 13 | * @returns 是 null 或 undefined 返回 true,否则返回 false 14 | */ 15 | export default function isNil(value: T): boolean { 16 | return value == null; 17 | } 18 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://typedoc.org/schema.json", 3 | "entryPoints": [ 4 | "src" 5 | ], 6 | "entryPointStrategy": "expand", 7 | "outputFileStrategy": "modules", 8 | "entryFileName": "entry", 9 | "plugin": [ 10 | "typedoc-plugin-markdown", 11 | ], 12 | "out": "docs/en/api", 13 | "readme": "none", 14 | "tsconfig": "./tsconfig.typedoc.json" 15 | } -------------------------------------------------------------------------------- /examples/vite3-demo/src/util/isError.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 检查是否是 Error 对象 4 | * 5 | * @example 6 | * ```js 7 | * isError(new Error()); // true 8 | * isError({}); // false 9 | * ``` 10 | * 11 | * @param value 待检查的值 12 | * @returns `true` 表示为 Error 对象,否则为 `false` 13 | */ 14 | export default function isError(value: any): value is Error { 15 | return Object.prototype.toString.call(value).indexOf('Error') > -1; 16 | } 17 | -------------------------------------------------------------------------------- /examples/vite4-demo/src/util/isError.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 检查是否是 Error 对象 4 | * 5 | * @example 6 | * ```js 7 | * isError(new Error()); // true 8 | * isError({}); // false 9 | * ``` 10 | * 11 | * @param value 待检查的值 12 | * @returns `true` 表示为 Error 对象,否则为 `false` 13 | */ 14 | export default function isError(value: any): value is Error { 15 | return Object.prototype.toString.call(value).indexOf('Error') > -1; 16 | } 17 | -------------------------------------------------------------------------------- /examples/vite5-demo/src/util/isError.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 检查是否是 Error 对象 4 | * 5 | * @example 6 | * ```js 7 | * isError(new Error()); // true 8 | * isError({}); // false 9 | * ``` 10 | * 11 | * @param value 待检查的值 12 | * @returns `true` 表示为 Error 对象,否则为 `false` 13 | */ 14 | export default function isError(value: any): value is Error { 15 | return Object.prototype.toString.call(value).indexOf('Error') > -1; 16 | } 17 | -------------------------------------------------------------------------------- /examples/vite6-demo/src/util/isError.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 检查是否是 Error 对象 4 | * 5 | * @example 6 | * ```js 7 | * isError(new Error()); // true 8 | * isError({}); // false 9 | * ``` 10 | * 11 | * @param value 待检查的值 12 | * @returns `true` 表示为 Error 对象,否则为 `false` 13 | */ 14 | export default function isError(value: any): value is Error { 15 | return Object.prototype.toString.call(value).indexOf('Error') > -1; 16 | } 17 | -------------------------------------------------------------------------------- /examples/vite3-demo/src/util/outputFile.js: -------------------------------------------------------------------------------- 1 | import { existsSync } from 'node:fs'; 2 | import { mkdir, writeFile } from 'node:fs/promises'; 3 | import { dirname } from 'node:path'; 4 | 5 | export async function outputFile(file, data, options = 'utf-8') { 6 | const dir = dirname(file); 7 | 8 | if (!existsSync(dir)) { 9 | await mkdir(dir, { recursive: true }); 10 | } 11 | 12 | return writeFile(file, data, options); 13 | } 14 | -------------------------------------------------------------------------------- /examples/vite4-demo/src/util/outputFile.js: -------------------------------------------------------------------------------- 1 | import { existsSync } from 'node:fs'; 2 | import { mkdir, writeFile } from 'node:fs/promises'; 3 | import { dirname } from 'node:path'; 4 | 5 | export async function outputFile(file, data, options = 'utf-8') { 6 | const dir = dirname(file); 7 | 8 | if (!existsSync(dir)) { 9 | await mkdir(dir, { recursive: true }); 10 | } 11 | 12 | return writeFile(file, data, options); 13 | } 14 | -------------------------------------------------------------------------------- /examples/vite5-demo/src/util/outputFile.js: -------------------------------------------------------------------------------- 1 | import { existsSync } from 'node:fs'; 2 | import { mkdir, writeFile } from 'node:fs/promises'; 3 | import { dirname } from 'node:path'; 4 | 5 | export async function outputFile(file, data, options = 'utf-8') { 6 | const dir = dirname(file); 7 | 8 | if (!existsSync(dir)) { 9 | await mkdir(dir, { recursive: true }); 10 | } 11 | 12 | return writeFile(file, data, options); 13 | } 14 | -------------------------------------------------------------------------------- /examples/vite6-demo/src/util/outputFile.js: -------------------------------------------------------------------------------- 1 | import { existsSync } from 'node:fs'; 2 | import { mkdir, writeFile } from 'node:fs/promises'; 3 | import { dirname } from 'node:path'; 4 | 5 | export async function outputFile(file, data, options = 'utf-8') { 6 | const dir = dirname(file); 7 | 8 | if (!existsSync(dir)) { 9 | await mkdir(dir, { recursive: true }); 10 | } 11 | 12 | return writeFile(file, data, options); 13 | } 14 | -------------------------------------------------------------------------------- /examples/vite3-demo/src/util/isNumber.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 检查是否是数字 3 | * 4 | * @example 5 | * ```js 6 | * isNumber(1); // true 7 | * isNumber({}); // false 8 | * ``` 9 | * 10 | * @param value 要检查的值 11 | * @returns 如果是数字返回 `true`,否则返回 `false` 12 | */ 13 | export default function isNumber(value: T): boolean { 14 | // eslint-disable-next-line no-self-compare 15 | return typeof value === 'number' && value === value; 16 | } 17 | -------------------------------------------------------------------------------- /examples/vite4-demo/src/util/isNumber.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 检查是否是数字 3 | * 4 | * @example 5 | * ```js 6 | * isNumber(1); // true 7 | * isNumber({}); // false 8 | * ``` 9 | * 10 | * @param value 要检查的值 11 | * @returns 如果是数字返回 `true`,否则返回 `false` 12 | */ 13 | export default function isNumber(value: T): boolean { 14 | // eslint-disable-next-line no-self-compare 15 | return typeof value === 'number' && value === value; 16 | } 17 | -------------------------------------------------------------------------------- /examples/vite5-demo/src/util/isNumber.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 检查是否是数字 3 | * 4 | * @example 5 | * ```js 6 | * isNumber(1); // true 7 | * isNumber({}); // false 8 | * ``` 9 | * 10 | * @param value 要检查的值 11 | * @returns 如果是数字返回 `true`,否则返回 `false` 12 | */ 13 | export default function isNumber(value: T): boolean { 14 | // eslint-disable-next-line no-self-compare 15 | return typeof value === 'number' && value === value; 16 | } 17 | -------------------------------------------------------------------------------- /examples/vite6-demo/src/util/isNumber.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 检查是否是数字 3 | * 4 | * @example 5 | * ```js 6 | * isNumber(1); // true 7 | * isNumber({}); // false 8 | * ``` 9 | * 10 | * @param value 要检查的值 11 | * @returns 如果是数字返回 `true`,否则返回 `false` 12 | */ 13 | export default function isNumber(value: T): boolean { 14 | // eslint-disable-next-line no-self-compare 15 | return typeof value === 'number' && value === value; 16 | } 17 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/typedoc.zh.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://typedoc.org/schema.json", 3 | "entryPoints": [ 4 | "src" 5 | ], 6 | "entryPointStrategy": "expand", 7 | "outputFileStrategy": "modules", 8 | "entryFileName": "entry", 9 | "lang": "zh", 10 | "plugin": [ 11 | "typedoc-plugin-markdown", 12 | ], 13 | "out": "docs/zh/api", 14 | "readme": "none", 15 | "tsconfig": "./tsconfig.typedoc.json" 16 | } -------------------------------------------------------------------------------- /examples/config/vite.hook-use.1.mts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite'; 2 | import vitePluginHookUse from 'vite-plugin-hook-use'; 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [ 7 | vitePluginHookUse() 8 | ], 9 | build: { 10 | outDir: 'dist/hook-use', 11 | lib: { 12 | entry: 'src/util/noop.ts', 13 | formats: ['es'], 14 | fileName: 'hook-use' 15 | } 16 | } 17 | }); 18 | -------------------------------------------------------------------------------- /examples/vite3-demo/src/util/isAsyncFunction.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 检查值是否为异步函数 4 | * 5 | * @example 6 | * ```js 7 | * isAsyncFunction(async () => { }); //true 8 | * isAsyncFunction(() => { }); //false 9 | * ``` 10 | * 11 | * @param value 待校验的值 12 | * @returns `true` 表示为异步函数,否则为 `false` 13 | */ 14 | export default function isAsyncFunction(value: T): value is T { 15 | return Object.prototype.toString.call(value) === '[object AsyncFunction]'; 16 | } 17 | -------------------------------------------------------------------------------- /examples/vite4-demo/src/util/isAsyncFunction.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 检查值是否为异步函数 4 | * 5 | * @example 6 | * ```js 7 | * isAsyncFunction(async () => { }); //true 8 | * isAsyncFunction(() => { }); //false 9 | * ``` 10 | * 11 | * @param value 待校验的值 12 | * @returns `true` 表示为异步函数,否则为 `false` 13 | */ 14 | export default function isAsyncFunction(value: T): value is T { 15 | return Object.prototype.toString.call(value) === '[object AsyncFunction]'; 16 | } 17 | -------------------------------------------------------------------------------- /examples/vite5-demo/src/util/isAsyncFunction.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 检查值是否为异步函数 4 | * 5 | * @example 6 | * ```js 7 | * isAsyncFunction(async () => { }); //true 8 | * isAsyncFunction(() => { }); //false 9 | * ``` 10 | * 11 | * @param value 待校验的值 12 | * @returns `true` 表示为异步函数,否则为 `false` 13 | */ 14 | export default function isAsyncFunction(value: T): value is T { 15 | return Object.prototype.toString.call(value) === '[object AsyncFunction]'; 16 | } 17 | -------------------------------------------------------------------------------- /examples/vite6-demo/src/util/isAsyncFunction.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 检查值是否为异步函数 4 | * 5 | * @example 6 | * ```js 7 | * isAsyncFunction(async () => { }); //true 8 | * isAsyncFunction(() => { }); //false 9 | * ``` 10 | * 11 | * @param value 待校验的值 12 | * @returns `true` 表示为异步函数,否则为 `false` 13 | */ 14 | export default function isAsyncFunction(value: T): value is T { 15 | return Object.prototype.toString.call(value) === '[object AsyncFunction]'; 16 | } 17 | -------------------------------------------------------------------------------- /examples/vite5-demo/r/index.jsx: -------------------------------------------------------------------------------- 1 | import '../index.css'; 2 | 3 | import React, { useState, version } from 'react'; 4 | import ReactDOM from 'react-dom'; 5 | 6 | function App() { 7 | const [count, setCount] = useState(0); 8 | return ( 9 | <> 10 |

{version}

11 |

Count: {count}

12 | 13 | 14 | ); 15 | } 16 | 17 | ReactDOM.render( 18 | , 19 | document.getElementById('root') 20 | ); 21 | -------------------------------------------------------------------------------- /examples/vite6-demo/src/index.jsx: -------------------------------------------------------------------------------- 1 | import './index.css'; 2 | 3 | import React, { useState, version } from 'react'; 4 | import ReactDOM from 'react-dom'; 5 | 6 | function App() { 7 | const [count, setCount] = useState(0); 8 | return ( 9 | <> 10 |

{version}

11 |

Count: {count}

12 | 13 | 14 | ); 15 | } 16 | 17 | ReactDOM.render( 18 | , 19 | document.getElementById('root') 20 | ); 21 | -------------------------------------------------------------------------------- /docs/.vitepress/theme/index.ts: -------------------------------------------------------------------------------- 1 | // https://vitepress.dev/guide/custom-theme 2 | import { h } from 'vue' 3 | import type { Theme } from 'vitepress' 4 | import DefaultTheme from 'vitepress/theme' 5 | import './style.css' 6 | 7 | export default { 8 | extends: DefaultTheme, 9 | Layout: () => { 10 | return h(DefaultTheme.Layout, null, { 11 | // https://vitepress.dev/guide/extending-default-theme#layout-slots 12 | }) 13 | }, 14 | enhanceApp({ app, router, siteData }) { 15 | // ... 16 | } 17 | } satisfies Theme 18 | -------------------------------------------------------------------------------- /examples/vite3-view/r/index.jsx: -------------------------------------------------------------------------------- 1 | import { StrictMode, useState, version } from 'react'; 2 | import { createRoot } from 'react-dom/client'; 3 | function App() { 4 | const [count, setCount] = useState(0); 5 | return ( 6 |
7 |

Count: {count}

8 | 9 |
10 | ); 11 | } 12 | 13 | createRoot(document.getElementById('root')).render( 14 | 15 | {version} 16 | 17 | , 18 | ); 19 | -------------------------------------------------------------------------------- /examples/vite4-view/r/index.jsx: -------------------------------------------------------------------------------- 1 | import { StrictMode, useState, version } from 'react'; 2 | import { createRoot } from 'react-dom/client'; 3 | function App() { 4 | const [count, setCount] = useState(0); 5 | return ( 6 |
7 |

Count: {count}

8 | 9 |
10 | ); 11 | } 12 | 13 | createRoot(document.getElementById('root')).render( 14 | 15 | {version} 16 | 17 | , 18 | ); 19 | -------------------------------------------------------------------------------- /examples/vite5-view/r/index.jsx: -------------------------------------------------------------------------------- 1 | import { StrictMode, useState, version } from 'react'; 2 | import { createRoot } from 'react-dom/client'; 3 | function App() { 4 | const [count, setCount] = useState(0); 5 | return ( 6 |
7 |

Count: {count}

8 | 9 |
10 | ); 11 | } 12 | 13 | createRoot(document.getElementById('root')).render( 14 | 15 | {version} 16 | 17 | , 18 | ); 19 | -------------------------------------------------------------------------------- /examples/vite6-demo/src/index2.jsx: -------------------------------------------------------------------------------- 1 | import { StrictMode, useState, version } from 'react'; 2 | import { createRoot } from 'react-dom/client'; 3 | function App() { 4 | const [count, setCount] = useState(0); 5 | return ( 6 |
7 |

Count: {count}

8 | 9 |
10 | ); 11 | } 12 | 13 | createRoot(document.getElementById('root')).render( 14 | 15 | {version} 16 | 17 | , 18 | ); 19 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/vite.config.mts: -------------------------------------------------------------------------------- 1 | import ts from '@rollup/plugin-typescript'; 2 | import { globSync } from 'tinyglobby'; 3 | import { defineConfig } from 'vite'; 4 | 5 | // https://vitejs.dev/config/ 6 | export default defineConfig({ 7 | plugins: [ 8 | ts({ 9 | tsconfig: './tsconfig.build.json' 10 | }) 11 | ], 12 | build: { 13 | lib: { 14 | entry: globSync(['./src/*.ts', '!./src/types.ts']), 15 | formats: ['es', 'cjs'], 16 | fileName: '[name]' 17 | }, 18 | minify: false 19 | } 20 | }); 21 | -------------------------------------------------------------------------------- /examples/vite3-demo/mock/test.ts: -------------------------------------------------------------------------------- 1 | export default { 2 | '/world': 'world', 3 | 4 | '/world2'(req, res) { 5 | res.statusCode = 200; 6 | res.setHeader('Content-Type', 'text/html'); 7 | res.end('world2'); 8 | }, 9 | 10 | '/world3': { 11 | handler(req, res) { 12 | res.statusCode = 200; 13 | res.setHeader('Content-Type', 'text/html'); 14 | res.end('world3'); 15 | } 16 | }, 17 | 18 | '/json2': { 19 | handler: { world: 1 } 20 | }, 21 | 22 | '/package2': { 23 | file: './package.json' 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /examples/vite4-demo/mock/test.ts: -------------------------------------------------------------------------------- 1 | export default { 2 | '/world': 'world', 3 | 4 | '/world2'(req, res) { 5 | res.statusCode = 200; 6 | res.setHeader('Content-Type', 'text/html'); 7 | res.end('world2'); 8 | }, 9 | 10 | '/world3': { 11 | handler(req, res) { 12 | res.statusCode = 200; 13 | res.setHeader('Content-Type', 'text/html'); 14 | res.end('world3'); 15 | } 16 | }, 17 | 18 | '/json2': { 19 | handler: { world: 1 } 20 | }, 21 | 22 | '/package2': { 23 | file: './package.json' 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /examples/vite5-demo/mock/test.ts: -------------------------------------------------------------------------------- 1 | export default { 2 | '/world': 'world', 3 | 4 | '/world2'(req, res) { 5 | res.statusCode = 200; 6 | res.setHeader('Content-Type', 'text/html'); 7 | res.end('world2'); 8 | }, 9 | 10 | '/world3': { 11 | handler(req, res) { 12 | res.statusCode = 200; 13 | res.setHeader('Content-Type', 'text/html'); 14 | res.end('world3'); 15 | } 16 | }, 17 | 18 | '/json2': { 19 | handler: { world: 1 } 20 | }, 21 | 22 | '/package2': { 23 | file: './package.json' 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /examples/vite6-demo/mock/test.ts: -------------------------------------------------------------------------------- 1 | export default { 2 | '/world': 'world', 3 | 4 | '/world2'(req, res) { 5 | res.statusCode = 200; 6 | res.setHeader('Content-Type', 'text/html'); 7 | res.end('world2'); 8 | }, 9 | 10 | '/world3': { 11 | handler(req, res) { 12 | res.statusCode = 200; 13 | res.setHeader('Content-Type', 'text/html'); 14 | res.end('world3'); 15 | } 16 | }, 17 | 18 | '/json2': { 19 | handler: { world: 1 } 20 | }, 21 | 22 | '/package2': { 23 | file: './package.json' 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/docs/.vitepress/theme/index.ts: -------------------------------------------------------------------------------- 1 | // https://vitepress.dev/guide/custom-theme 2 | import { h } from 'vue' 3 | import type { Theme } from 'vitepress' 4 | import DefaultTheme from 'vitepress/theme' 5 | import './style.css' 6 | 7 | export default { 8 | extends: DefaultTheme, 9 | Layout: () => { 10 | return h(DefaultTheme.Layout, null, { 11 | // https://vitepress.dev/guide/extending-default-theme#layout-slots 12 | }) 13 | }, 14 | enhanceApp({ app, router, siteData }) { 15 | // ... 16 | } 17 | } satisfies Theme 18 | -------------------------------------------------------------------------------- /packages/vp-runtime-helper/src/hash.ts: -------------------------------------------------------------------------------- 1 | import crypto from 'node:crypto'; 2 | 3 | const hash 4 | = (crypto as any).hash 5 | ?? (( 6 | algorithm: string, 7 | data: crypto.BinaryLike, 8 | outputEncoding: crypto.BinaryToTextEncoding, 9 | ) => crypto.createHash(algorithm).update(data).digest(outputEncoding)); 10 | 11 | export function getHash(text: Buffer | string, length = 8): string { 12 | const h = hash('sha256', text, 'hex').substring(0, length); 13 | if (length <= 64) { 14 | return h; 15 | } 16 | return h.padEnd(length, '_'); 17 | } 18 | -------------------------------------------------------------------------------- /examples/vite5-demo/r/index2.jsx: -------------------------------------------------------------------------------- 1 | import '../index.css'; 2 | 3 | import { StrictMode, useState, version } from 'react'; 4 | import { createRoot } from 'react-dom/client'; 5 | function App() { 6 | const [count, setCount] = useState(0); 7 | return ( 8 |
9 |

Count: {count}

10 | 11 |
12 | ); 13 | } 14 | 15 | createRoot(document.getElementById('root')).render( 16 | 17 | {version} 18 | 19 | , 20 | ); 21 | -------------------------------------------------------------------------------- /examples/vite6-view/index.pug: -------------------------------------------------------------------------------- 1 | doctype html 2 | html(lang='en') 3 | head 4 | meta(charset='UTF-8') 5 | meta(content='width=device-width, initial-scale=1.0' name='viewport') 6 | title= title 7 | link(href='./index.css' rel='stylesheet') 8 | body 9 | //- ResolvedConfig 来自 configResolved 钩子 10 | p 11 | | define: 12 | = JSON.stringify(ResolvedConfig.define, null, 2) 13 | p 14 | | env: 15 | = JSON.stringify(ResolvedConfig.env, null, 2) 16 | #root 17 | script(src='//unpkg.com/vue@3.5.13/dist/vue.runtime.global.js') 18 | script(src='./v/main.ts' type='module') -------------------------------------------------------------------------------- /packages/vp-runtime-helper/README.md: -------------------------------------------------------------------------------- 1 | # vp-runtime-helper 2 | 3 | [![npm package](https://nodei.co/npm/vp-runtime-helper.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/vp-runtime-helper) 4 | 5 | > Helper functions for Vite plugins. 6 | 7 | [![NPM version](https://img.shields.io/npm/v/vp-runtime-helper.svg?style=flat)](https://npmjs.org/package/vp-runtime-helper) 8 | [![NPM Downloads](https://img.shields.io/npm/dm/vp-runtime-helper.svg?style=flat)](https://npmjs.org/package/vp-runtime-helper) 9 | 10 | ## Installation 11 | 12 | ```bash 13 | npm install vp-runtime-helper --save 14 | ``` -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/src/isNil.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Checks if `value` is `null` or `undefined`. 3 | * 4 | * @param {*} value The value to check. 5 | * @returns {boolean} Returns `true` if `value` is nullish, else `false`. 6 | * @example 7 | * ```ts 8 | * isNil(null) 9 | * // => true 10 | * 11 | * isNil(void 0) 12 | * // => true 13 | * 14 | * isNil(NaN) 15 | * //=> false 16 | * ``` 17 | * @param value The value to check. 18 | * @returns `true` if `value` is nullish, else `false`. 19 | */ 20 | export default function isNil(value: unknown): value is null | undefined { 21 | return value == null; 22 | } 23 | -------------------------------------------------------------------------------- /packages/cs-runtime-helper/README.md: -------------------------------------------------------------------------------- 1 | # cs-runtime-helper 2 | 3 | [![npm package](https://nodei.co/npm/cs-runtime-helper.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/cs-runtime-helper) 4 | 5 | > Helper functions used when developing create starter 6 | 7 | [![NPM version](https://img.shields.io/npm/v/cs-runtime-helper.svg?style=flat)](https://npmjs.org/package/cs-runtime-helper) 8 | [![NPM Downloads](https://img.shields.io/npm/dm/cs-runtime-helper.svg?style=flat)](https://npmjs.org/package/cs-runtime-helper) 9 | 10 | ## Installation 11 | 12 | ```bash 13 | npm install cs-runtime-helper --save 14 | ``` -------------------------------------------------------------------------------- /packages/vite-plugin-reverse-proxy/vite.config.mts: -------------------------------------------------------------------------------- 1 | import ts from '@rollup/plugin-typescript'; 2 | import { defineConfig } from 'vite'; 3 | import pluginExternal from 'vite-plugin-external'; 4 | 5 | const externalizeDeps = ['vite']; 6 | 7 | // https://vitejs.dev/config/ 8 | export default defineConfig({ 9 | plugins: [ 10 | pluginExternal({ 11 | nodeBuiltins: true, 12 | externalizeDeps 13 | }), 14 | ts({ 15 | tsconfig: './tsconfig.build.json' 16 | }) 17 | ], 18 | build: { 19 | lib: { 20 | entry: 'src/index.ts', 21 | formats: ['es', 'cjs'], 22 | fileName: 'index' 23 | }, 24 | minify: false 25 | } 26 | }); 27 | -------------------------------------------------------------------------------- /packages/vp-runtime-helper/src/time.ts: -------------------------------------------------------------------------------- 1 | export function displayTime(time: number): string { 2 | // display: {X}ms 3 | if (time < 1000) { 4 | return `${time}ms`; 5 | } 6 | 7 | time = time / 1000; 8 | 9 | // display: {X}s 10 | if (time < 60) { 11 | return `${time.toFixed(2)}s`; 12 | } 13 | 14 | // Calculate total minutes and remaining seconds 15 | const mins = Math.floor(time / 60); 16 | const seconds = Math.round(time % 60); 17 | 18 | // Handle case where seconds rounds to 60 19 | if (seconds === 60) { 20 | return `${mins + 1}m`; 21 | } 22 | 23 | // display: {X}m {Y}s 24 | return `${mins}m${seconds < 1 ? '' : ` ${seconds}s`}`; 25 | } 26 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "sourceMap": false, 5 | "target": "ES2017", 6 | "module": "ESNext", 7 | "moduleResolution": "bundler", 8 | "newLine": "LF", 9 | "strict": true, 10 | 11 | "allowJs": true, 12 | "noImplicitAny": false, 13 | "noImplicitThis": false, 14 | 15 | "noUnusedLocals": true, 16 | "experimentalDecorators": true, 17 | "resolveJsonModule": true, 18 | "isolatedModules": true, 19 | "skipLibCheck": true, 20 | "esModuleInterop": true, 21 | "removeComments": false, 22 | "jsx": "preserve", 23 | "lib": ["ESNext"], 24 | "types": ["node"] 25 | } 26 | } -------------------------------------------------------------------------------- /examples/vite5-view/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite5-view", 3 | "private": true, 4 | "version": "0.1.0", 5 | "type": "module", 6 | "scripts": { 7 | "build:view.5": "vite build --config=../config/vite.view.5.mts", 8 | "dev:view.5": "vite dev --config=../config/vite.view.5.mts", 9 | "preview:view.5": "vite preview --config=../config/vite.view.5.mts" 10 | }, 11 | "devDependencies": { 12 | "@rollup/plugin-typescript": "^12.1.2", 13 | "@vitejs/plugin-react": "^4.3.4", 14 | "ejs": "^3.1.10", 15 | "vite": "^5.0.0", 16 | "vite-plugin-external": "workspace:^", 17 | "vite-plugin-view": "workspace:^" 18 | }, 19 | "repository": "https://github.com/fengxinming/vite-plugins.git" 20 | } -------------------------------------------------------------------------------- /examples/vite6-view/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite6-view", 3 | "private": true, 4 | "version": "0.1.0", 5 | "type": "module", 6 | "scripts": { 7 | "build:view.6": "vite build --config=../config/vite.view.6.mts", 8 | "dev:view.6": "vite dev --config=../config/vite.view.6.mts", 9 | "preview:view.6": "vite preview --config=../config/vite.view.6.mts" 10 | }, 11 | "devDependencies": { 12 | "@rollup/plugin-typescript": "^12.1.2", 13 | "@vitejs/plugin-vue": "^5.2.3", 14 | "pug": "^3.0.3", 15 | "vite": "^6.0.0", 16 | "vite-plugin-external": "workspace:^", 17 | "vite-plugin-view": "workspace:^" 18 | }, 19 | "repository": "https://github.com/fengxinming/vite-plugins.git" 20 | } -------------------------------------------------------------------------------- /examples/vite3-view/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite3-view", 3 | "private": true, 4 | "version": "0.1.0", 5 | "type": "module", 6 | "scripts": { 7 | "build:view.3": "vite build --config=../config/vite.view.3.mts", 8 | "dev:view.3": "vite dev --config=../config/vite.view.3.mts", 9 | "preview:view.3": "vite preview --config=../config/vite.view.3.mts" 10 | }, 11 | "devDependencies": { 12 | "@rollup/plugin-typescript": "^12.1.2", 13 | "@vitejs/plugin-react": "^2.2.0", 14 | "nunjucks": "^3.2.4", 15 | "vite": "^3.1.0", 16 | "vite-plugin-external": "workspace:^", 17 | "vite-plugin-view": "workspace:^" 18 | }, 19 | "repository": "https://github.com/fengxinming/vite-plugins.git" 20 | } -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/docs/zh/api/isNil.md: -------------------------------------------------------------------------------- 1 | [**create-vite-lib-starter**](entry.md) 2 | 3 | *** 4 | 5 | [create-vite-lib-starter](entry.md) / isNil 6 | 7 | # isNil 8 | 9 | ## 函数 10 | 11 | ### default() 12 | 13 | > **default**(`value`): value is undefined \| null 14 | 15 | 定义于: isNil.ts:20 16 | 17 | Checks if `value` is `null` or `undefined`. 18 | 19 | #### 参数 20 | 21 | ##### value 22 | 23 | `unknown` 24 | 25 | The value to check. 26 | 27 | #### 返回 28 | 29 | value is undefined \| null 30 | 31 | Returns `true` if `value` is nullish, else `false`. 32 | 33 | #### 示例 34 | 35 | ```ts 36 | isNil(null) 37 | // => true 38 | 39 | isNil(void 0) 40 | // => true 41 | 42 | isNil(NaN) 43 | //=> false 44 | ``` 45 | -------------------------------------------------------------------------------- /examples/config/vite.external.9.mts: -------------------------------------------------------------------------------- 1 | import { globSync } from 'tinyglobby'; 2 | import { defineConfig } from 'vite'; 3 | import vitePluginExternal from 'vite-plugin-external'; 4 | 5 | // https://vitejs.dev/config/ 6 | export default defineConfig({ 7 | plugins: [ 8 | vitePluginExternal({ 9 | logLevel: 'TRACE', 10 | nodeBuiltins: true, 11 | externalizeDeps: ['vite'] 12 | }) 13 | ], 14 | build: { 15 | outDir: 'dist/external/9', 16 | minify: false, 17 | lib: { 18 | formats: ['es', 'cjs'], 19 | entry: globSync('src/util/*.js'), 20 | fileName(format, entryName) { 21 | return entryName + (format === 'es' ? '.mjs' : '.js'); 22 | } 23 | } 24 | } 25 | }); 26 | -------------------------------------------------------------------------------- /examples/vite4-view/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite4-view", 3 | "private": true, 4 | "version": "0.1.0", 5 | "type": "module", 6 | "scripts": { 7 | "build:view.4": "vite build --config=../config/vite.view.4.mts", 8 | "dev:view.4": "vite dev --config=../config/vite.view.4.mts", 9 | "preview:view.4": "vite preview --config=../config/vite.view.4.mts" 10 | }, 11 | "devDependencies": { 12 | "@rollup/plugin-typescript": "^12.1.2", 13 | "@vitejs/plugin-react": "^4.3.4", 14 | "handlebars": "^4.7.8", 15 | "vite": "^4.5.0", 16 | "vite-plugin-external": "workspace:^", 17 | "vite-plugin-view": "workspace:^" 18 | }, 19 | "repository": "https://github.com/fengxinming/vite-plugins.git" 20 | } -------------------------------------------------------------------------------- /packages/vite-plugin-mock-data/vite.config.mts: -------------------------------------------------------------------------------- 1 | import ts from '@rollup/plugin-typescript'; 2 | import { defineConfig } from 'vite'; 3 | import pluginExternal from 'vite-plugin-external'; 4 | 5 | import pkg from './package.json'; 6 | 7 | export default defineConfig({ 8 | plugins: [ 9 | ts({ 10 | tsconfig: './tsconfig.build.json' 11 | }), 12 | pluginExternal({ 13 | nodeBuiltins: true, 14 | externalizeDeps: Object.keys(pkg.dependencies) 15 | }) 16 | ], 17 | build: { 18 | rollupOptions: { 19 | external: ['vite'] 20 | }, 21 | lib: { 22 | entry: 'src/index.ts', 23 | formats: ['es', 'cjs'], 24 | fileName: 'index' 25 | }, 26 | minify: false 27 | } 28 | }); 29 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/docs/en/api/isNil.md: -------------------------------------------------------------------------------- 1 | [**create-vite-lib-starter**](entry.md) 2 | 3 | *** 4 | 5 | [create-vite-lib-starter](entry.md) / isNil 6 | 7 | # isNil 8 | 9 | ## Functions 10 | 11 | ### default() 12 | 13 | > **default**(`value`): value is undefined \| null 14 | 15 | Defined in: isNil.ts:20 16 | 17 | Checks if `value` is `null` or `undefined`. 18 | 19 | #### Parameters 20 | 21 | ##### value 22 | 23 | `unknown` 24 | 25 | The value to check. 26 | 27 | #### Returns 28 | 29 | value is undefined \| null 30 | 31 | Returns `true` if `value` is nullish, else `false`. 32 | 33 | #### Example 34 | 35 | ```ts 36 | isNil(null) 37 | // => true 38 | 39 | isNil(void 0) 40 | // => true 41 | 42 | isNil(NaN) 43 | //=> false 44 | ``` 45 | -------------------------------------------------------------------------------- /tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "sourceMap": false, 5 | "target": "ESNext", 6 | "module": "ESNext", 7 | "moduleResolution": "bundler", 8 | "newLine": "LF", 9 | "strict": true, 10 | 11 | "allowJs": true, 12 | "noImplicitAny": false, 13 | "noImplicitThis": false, 14 | 15 | "noUnusedLocals": true, 16 | "experimentalDecorators": true, 17 | "resolveJsonModule": true, 18 | "isolatedModules": true, 19 | "skipLibCheck": true, 20 | "esModuleInterop": true, 21 | "removeComments": false, 22 | "jsx": "preserve", 23 | "lib": ["esnext", "dom"], 24 | "types": ["node"] 25 | }, 26 | "exclude": [ 27 | "dist", 28 | "node_modules" 29 | ] 30 | } -------------------------------------------------------------------------------- /packages/vite-plugin-cp/vite.config.mts: -------------------------------------------------------------------------------- 1 | import ts from '@rollup/plugin-typescript'; 2 | import { defineConfig } from 'vite'; 3 | import pluginExternal from 'vite-plugin-external'; 4 | 5 | import pkg from './package.json'; 6 | 7 | // https://vitejs.dev/config/ 8 | export default defineConfig({ 9 | plugins: [ 10 | pluginExternal({ 11 | nodeBuiltins: true, 12 | externalizeDeps: Object.keys(pkg.dependencies) 13 | }), 14 | ts({ 15 | tsconfig: './tsconfig.build.json' 16 | }) 17 | ], 18 | build: { 19 | rollupOptions: { 20 | external: ['vite'] 21 | }, 22 | lib: { 23 | entry: 'src/index.ts', 24 | formats: ['es', 'cjs'], 25 | fileName: '[name]' 26 | }, 27 | minify: false 28 | } 29 | }); 30 | -------------------------------------------------------------------------------- /packages/vite-plugin-hook-use/vite.config.mts: -------------------------------------------------------------------------------- 1 | import ts from '@rollup/plugin-typescript'; 2 | import { defineConfig } from 'vite'; 3 | import pluginExternal from 'vite-plugin-external'; 4 | 5 | import pkg from './package.json'; 6 | 7 | // https://vitejs.dev/config/ 8 | export default defineConfig({ 9 | plugins: [ 10 | pluginExternal({ 11 | nodeBuiltins: true, 12 | externalizeDeps: Object.keys(pkg.dependencies) 13 | }), 14 | ts({ 15 | tsconfig: './tsconfig.build.json' 16 | }) 17 | ], 18 | build: { 19 | rollupOptions: { 20 | external: ['vite'] 21 | }, 22 | lib: { 23 | entry: 'src/index.ts', 24 | formats: ['es', 'cjs'], 25 | fileName: 'index' 26 | }, 27 | minify: false 28 | } 29 | }); 30 | -------------------------------------------------------------------------------- /examples/config/vite.combine.1.mts: -------------------------------------------------------------------------------- 1 | import { defineConfig, PluginOption } from 'vite'; 2 | import vitePluginCombine from 'vite-plugin-combine'; 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [ 7 | vitePluginCombine({ 8 | logLevel: 'TRACE', 9 | src: ['src/util/*.ts', '!src/util/typings.ts'], 10 | target: 'src/combine.1.ts', 11 | nameExport: true, 12 | dts: true 13 | }) as unknown as PluginOption 14 | ], 15 | build: { 16 | outDir: 'dist/combine/1', 17 | minify: false, 18 | lib: { 19 | entry: [], 20 | formats: ['es', 'cjs'], 21 | fileName(format, entryName) { 22 | return entryName + (format === 'es' ? '.mjs' : '.js'); 23 | } 24 | } 25 | } 26 | }); 27 | -------------------------------------------------------------------------------- /examples/config/vite.combine.3.mts: -------------------------------------------------------------------------------- 1 | import { defineConfig, PluginOption } from 'vite'; 2 | import vitePluginCombine from 'vite-plugin-combine'; 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [ 7 | vitePluginCombine({ 8 | logLevel: 'TRACE', 9 | src: ['src/util/*.ts', '!src/util/typings.ts'], 10 | target: 'src/combine.3.ts', 11 | exports: 'both', 12 | dts: true 13 | }) as unknown as PluginOption 14 | ], 15 | build: { 16 | outDir: 'dist/combine/3', 17 | minify: false, 18 | lib: { 19 | entry: [], 20 | formats: ['es', 'cjs'], 21 | fileName(format, entryName) { 22 | return entryName + (format === 'es' ? '.mjs' : '.js'); 23 | } 24 | } 25 | } 26 | }); 27 | -------------------------------------------------------------------------------- /examples/config/vite.combine.6.mts: -------------------------------------------------------------------------------- 1 | import { defineConfig, PluginOption } from 'vite'; 2 | import vitePluginCombine from 'vite-plugin-combine'; 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [ 7 | vitePluginCombine({ 8 | logLevel: 'TRACE', 9 | src: ['src/util/*.ts', '!src/util/typings.ts'], 10 | target: 'src/combine.6.ts', 11 | exports: 'none', 12 | dts: true 13 | }) as unknown as PluginOption 14 | ], 15 | build: { 16 | outDir: 'dist/combine/6', 17 | minify: false, 18 | lib: { 19 | entry: [], 20 | formats: ['es', 'cjs'], 21 | fileName(format, entryName) { 22 | return entryName + (format === 'es' ? '.mjs' : '.js'); 23 | } 24 | } 25 | } 26 | }); 27 | -------------------------------------------------------------------------------- /examples/vite3-view/index.njk: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | {{ title }} 7 | 8 | 9 | 10 | {# ResolvedConfig 来自 configResolved 钩子 #} 11 |

alias: {{ ResolvedConfig.resolve.alias|stringify }}

12 |

env: {{ ResolvedConfig.env|stringify }}

13 |
14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /packages/vite-plugin-build-chunk/vite.config.mts: -------------------------------------------------------------------------------- 1 | import ts from '@rollup/plugin-typescript'; 2 | import { defineConfig } from 'vite'; 3 | import pluginExternal from 'vite-plugin-external'; 4 | 5 | import pkg from './package.json'; 6 | 7 | // https://vitejs.dev/config/ 8 | export default defineConfig({ 9 | plugins: [ 10 | pluginExternal({ 11 | nodeBuiltins: true, 12 | externalizeDeps: Object.keys(pkg.dependencies) 13 | }), 14 | ts({ 15 | tsconfig: './tsconfig.build.json' 16 | }) 17 | ], 18 | build: { 19 | rollupOptions: { 20 | external: ['vite'] 21 | }, 22 | lib: { 23 | entry: 'src/index.ts', 24 | formats: ['es', 'cjs'], 25 | fileName: 'index' 26 | }, 27 | minify: false 28 | } 29 | }); 30 | -------------------------------------------------------------------------------- /packages/vite-plugin-combine/vite.config.mts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite'; 2 | import dts from 'vite-plugin-dts'; 3 | import pluginExternal from 'vite-plugin-external'; 4 | 5 | import pkg from './package.json'; 6 | 7 | // https://vitejs.dev/config/ 8 | export default defineConfig({ 9 | plugins: [ 10 | dts({ 11 | entryRoot: 'src', 12 | include: 'src/*.ts' 13 | }), 14 | pluginExternal({ 15 | nodeBuiltins: true, 16 | externalizeDeps: Object.keys(pkg.dependencies) 17 | }) 18 | ], 19 | build: { 20 | rollupOptions: { 21 | external: ['vite'] 22 | }, 23 | lib: { 24 | entry: 'src/index.ts', 25 | formats: ['es', 'cjs'], 26 | fileName: 'index' 27 | }, 28 | minify: false 29 | } 30 | }); 31 | -------------------------------------------------------------------------------- /packages/vite-plugin-include-css/vite.config.mts: -------------------------------------------------------------------------------- 1 | import ts from '@rollup/plugin-typescript'; 2 | import { defineConfig } from 'vite'; 3 | import pluginExternal from 'vite-plugin-external'; 4 | 5 | import pkg from './package.json'; 6 | 7 | // https://vitejs.dev/config/ 8 | export default defineConfig({ 9 | plugins: [ 10 | pluginExternal({ 11 | nodeBuiltins: true, 12 | externalizeDeps: Object.keys(pkg.dependencies) 13 | }), 14 | ts({ 15 | tsconfig: './tsconfig.build.json' 16 | }) 17 | ], 18 | build: { 19 | rollupOptions: { 20 | external: ['vite'] 21 | }, 22 | lib: { 23 | entry: 'src/index.ts', 24 | formats: ['es', 'cjs'], 25 | fileName: 'index' 26 | }, 27 | minify: false 28 | } 29 | }); 30 | -------------------------------------------------------------------------------- /examples/config/vite.combine.2.mts: -------------------------------------------------------------------------------- 1 | import { defineConfig, PluginOption } from 'vite'; 2 | import vitePluginCombine from 'vite-plugin-combine'; 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [ 7 | vitePluginCombine({ 8 | logLevel: 'TRACE', 9 | src: ['src/util/*.ts', '!src/util/typings.ts'], 10 | target: 'src/combine.2.ts', 11 | exports: 'default', 12 | dts: true 13 | }) as unknown as PluginOption 14 | ], 15 | build: { 16 | outDir: 'dist/combine/2', 17 | minify: false, 18 | lib: { 19 | entry: [], 20 | formats: ['es', 'cjs'], 21 | fileName(format, entryName) { 22 | return entryName + (format === 'es' ? '.mjs' : '.js'); 23 | } 24 | } 25 | } 26 | }); 27 | -------------------------------------------------------------------------------- /examples/vite4-view/index.hbs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Vite + React 7 | 8 | 9 | 10 | {{! ResolvedConfig 来自 configResolved 钩子 }} 11 |

alias: {{ stringify ResolvedConfig.resolve.alias }}

12 |

env: {{ stringify ResolvedConfig.env }}

13 |
14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /packages/vite-plugin-separate-importer/vite.config.mts: -------------------------------------------------------------------------------- 1 | import ts from '@rollup/plugin-typescript'; 2 | import { defineConfig } from 'vite'; 3 | import pluginExternal from 'vite-plugin-external'; 4 | 5 | import pkg from './package.json'; 6 | 7 | // https://vitejs.dev/config/ 8 | export default defineConfig({ 9 | plugins: [ 10 | pluginExternal({ 11 | nodeBuiltins: true, 12 | externalizeDeps: Object.keys(pkg.dependencies) 13 | }), 14 | ts({ 15 | tsconfig: './tsconfig.build.json' 16 | }) 17 | ], 18 | build: { 19 | rollupOptions: { 20 | external: ['vite'] 21 | }, 22 | lib: { 23 | entry: 'src/index.ts', 24 | formats: ['es', 'cjs'], 25 | fileName: '[name]' 26 | }, 27 | minify: false 28 | } 29 | }); 30 | -------------------------------------------------------------------------------- /packages/vp-runtime-helper/src/devServer.ts: -------------------------------------------------------------------------------- 1 | import type { PreviewServer, ViteDevServer } from 'vite'; 2 | import { normalizePath } from 'vite'; 3 | export function isDevServer( 4 | server: ViteDevServer | PreviewServer, 5 | ): server is ViteDevServer { 6 | return 'pluginContainer' in server; 7 | } 8 | 9 | const VOLUME_RE = /^[A-Z]:/i; 10 | export const FS_PREFIX = '/@fs/'; 11 | export function fsPathFromId(id: string): string { 12 | const fsPath = normalizePath( 13 | id.startsWith(FS_PREFIX) ? id.slice(FS_PREFIX.length) : id, 14 | ); 15 | return fsPath.startsWith('/') || VOLUME_RE.test(fsPath) ? fsPath : `/${fsPath}`; 16 | } 17 | 18 | const postfixRE = /[?#].*$/; 19 | export function cleanUrl(url: string): string { 20 | return url.replace(postfixRE, ''); 21 | } 22 | -------------------------------------------------------------------------------- /examples/config/vite.combine.4.mts: -------------------------------------------------------------------------------- 1 | import { defineConfig, PluginOption } from 'vite'; 2 | import vitePluginCombine from 'vite-plugin-combine'; 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [ 7 | vitePluginCombine({ 8 | logLevel: 'TRACE', 9 | src: ['src/util/*.ts', '!src/util/typings.ts'], 10 | target: 'src/combine.4.ts', 11 | nameExport: (name) => `my${name}`, 12 | dts: true 13 | }) as unknown as PluginOption 14 | ], 15 | build: { 16 | outDir: 'dist/combine/4', 17 | minify: false, 18 | lib: { 19 | entry: [], 20 | formats: ['es', 'cjs'], 21 | fileName(format, entryName) { 22 | return entryName + (format === 'es' ? '.mjs' : '.js'); 23 | } 24 | } 25 | } 26 | }); 27 | -------------------------------------------------------------------------------- /examples/vite5-view/index.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | <%= title %> 7 | 8 | 9 | 10 | <%# ResolvedConfig 来自 configResolved 钩子 %> 11 |

alias: <%= JSON.stringify(ResolvedConfig.resolve.alias, null, 2) %>

12 |

env: <%= JSON.stringify(ResolvedConfig.env, null, 2) %>

13 |
14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /packages/vite-plugin-view/vite.config.mts: -------------------------------------------------------------------------------- 1 | import ts from '@rollup/plugin-typescript'; 2 | import { defineConfig, Plugin } from 'vite'; 3 | import pluginExternal from 'vite-plugin-external'; 4 | 5 | import pkg from './package.json'; 6 | 7 | 8 | // https://vitejs.dev/config/ 9 | export default defineConfig({ 10 | plugins: [ 11 | pluginExternal({ 12 | nodeBuiltins: true, 13 | externalizeDeps: Object.keys(pkg.dependencies) 14 | }), 15 | ts({ 16 | tsconfig: './tsconfig.build.json' 17 | }) as Plugin 18 | ], 19 | build: { 20 | rollupOptions: { 21 | external: Object.keys(pkg.devDependencies) 22 | }, 23 | lib: { 24 | entry: 'src/index.ts', 25 | formats: ['es', 'cjs'], 26 | fileName: 'index' 27 | }, 28 | minify: false 29 | } 30 | }); 31 | -------------------------------------------------------------------------------- /examples/vite6-demo/index3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Vite + React 7 | 8 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /packages/cs-runtime-helper/vite.config.mts: -------------------------------------------------------------------------------- 1 | import { builtinModules } from 'node:module'; 2 | 3 | import ts from '@rollup/plugin-typescript'; 4 | import { defineConfig } from 'vite'; 5 | 6 | import { dependencies } from './package.json'; 7 | 8 | const externals = Object.keys(dependencies) 9 | .concat(builtinModules, 'vite') 10 | .map((n) => new RegExp(`^${n}/?`)) 11 | .concat(/^node:/); 12 | 13 | // https://vitejs.dev/config/ 14 | export default defineConfig({ 15 | plugins: [ 16 | ts({ 17 | tsconfig: './tsconfig.build.json' 18 | }) 19 | ], 20 | build: { 21 | lib: { 22 | entry: 'src/index.ts', 23 | formats: ['es', 'cjs'], 24 | fileName: '[name]' 25 | }, 26 | minify: false, 27 | rollupOptions: { 28 | external: externals 29 | } 30 | } 31 | }); 32 | -------------------------------------------------------------------------------- /packages/vite-plugin-external/vite.config.mts: -------------------------------------------------------------------------------- 1 | import { builtinModules } from 'node:module'; 2 | 3 | import ts from '@rollup/plugin-typescript'; 4 | import { defineConfig } from 'vite'; 5 | 6 | import { dependencies } from './package.json'; 7 | 8 | const externals = Object.keys(dependencies) 9 | .concat(builtinModules, 'vite') 10 | .map((n) => new RegExp(`^${n}/?`)) 11 | .concat(/^node:/); 12 | 13 | // https://vitejs.dev/config/ 14 | export default defineConfig({ 15 | plugins: [ 16 | ts({ 17 | tsconfig: './tsconfig.build.json' 18 | }) 19 | ], 20 | build: { 21 | lib: { 22 | entry: 'src/index.ts', 23 | formats: ['es', 'cjs'], 24 | fileName: '[name]' 25 | }, 26 | minify: false, 27 | rollupOptions: { 28 | external: externals 29 | } 30 | } 31 | }); 32 | -------------------------------------------------------------------------------- /packages/vp-runtime-helper/vite.config.mts: -------------------------------------------------------------------------------- 1 | import { builtinModules } from 'node:module'; 2 | 3 | import ts from '@rollup/plugin-typescript'; 4 | import { defineConfig } from 'vite'; 5 | 6 | import { dependencies } from './package.json'; 7 | 8 | const externals = Object.keys(dependencies) 9 | .concat(builtinModules, 'vite') 10 | .map((n) => new RegExp(`^${n}/?`)) 11 | .concat(/^node:/); 12 | 13 | // https://vitejs.dev/config/ 14 | export default defineConfig({ 15 | plugins: [ 16 | ts({ 17 | tsconfig: './tsconfig.build.json' 18 | }) 19 | ], 20 | build: { 21 | lib: { 22 | entry: 'src/index.ts', 23 | formats: ['es', 'cjs'], 24 | fileName: '[name]' 25 | }, 26 | minify: false, 27 | rollupOptions: { 28 | external: externals 29 | } 30 | } 31 | }); 32 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/docs/zh/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | # https://vitepress.dev/reference/default-theme-home-page 3 | layout: home 4 | 5 | hero: 6 | name: create-vite-lib-starter 7 | text: 这里是描述 8 | tagline: 这里是标语 9 | actions: 10 | - theme: brand 11 | text: 介绍 12 | link: /zh/guide/introduction 13 | - theme: alt 14 | text: API 示例 15 | link: /zh/api 16 | image: 17 | src: https://vitepress.dev/vitepress-logo-large.svg 18 | alt: create-vite-lib-starter 19 | 20 | features: 21 | - title: Feature A 22 | details: Lorem ipsum dolor sit amet, consectetur adipiscing elit 23 | - title: Feature B 24 | details: Lorem ipsum dolor sit amet, consectetur adipiscing elit 25 | - title: Feature C 26 | details: Lorem ipsum dolor sit amet, consectetur adipiscing elit 27 | --- 28 | 29 | -------------------------------------------------------------------------------- /docs/zh/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | # https://vitepress.dev/reference/default-theme-home-page 3 | layout: home 4 | 5 | hero: 6 | name: vite-plugins 7 | text: 一个包含多个自定义插件的集合,用于增强 Vite 构建工具的功能。 8 | tagline: 快来尝试一下吧! 9 | actions: 10 | - theme: brand 11 | text: 引言 12 | link: /zh/guide/introduction 13 | # - theme: alt 14 | # text: API Examples 15 | # link: /api-examples 16 | image: 17 | src: https://vitepress.dev/vitepress-logo-large.svg 18 | alt: vite-plugins 19 | 20 | # features: 21 | # - title: Feature A 22 | # details: Lorem ipsum dolor sit amet, consectetur adipiscing elit 23 | # - title: Feature B 24 | # details: Lorem ipsum dolor sit amet, consectetur adipiscing elit 25 | # - title: Feature C 26 | # details: Lorem ipsum dolor sit amet, consectetur adipiscing elit 27 | --- 28 | 29 | -------------------------------------------------------------------------------- /examples/config/vite.combine.5.mts: -------------------------------------------------------------------------------- 1 | 2 | import { defineConfig, PluginOption } from 'vite'; 3 | import vitePluginCombine from 'vite-plugin-combine'; 4 | 5 | // https://vitejs.dev/config/ 6 | export default defineConfig({ 7 | plugins: [ 8 | vitePluginCombine({ 9 | logLevel: 'TRACE', 10 | src: ['src/util/*.ts', '!src/util/typings.ts'], 11 | target: 'src/combine.5.ts', 12 | beforeWrite(code) { 13 | return `${code}export * from './util/typings';`; 14 | }, 15 | dts: true 16 | }) as unknown as PluginOption 17 | ], 18 | build: { 19 | outDir: 'dist/combine/5', 20 | minify: false, 21 | lib: { 22 | entry: [], 23 | formats: ['es', 'cjs'], 24 | fileName(format, entryName) { 25 | return entryName + (format === 'es' ? '.mjs' : '.js'); 26 | } 27 | } 28 | } 29 | }); 30 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/docs/en/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | # https://vitepress.dev/reference/default-theme-home-page 3 | layout: home 4 | 5 | hero: 6 | name: create-vite-lib-starter 7 | text: Here is description. 8 | tagline: Here is tagline! 9 | actions: 10 | - theme: brand 11 | text: Introduction 12 | link: /guide/introduction 13 | - theme: alt 14 | text: API Examples 15 | link: /api/entry 16 | image: 17 | src: https://vitepress.dev/vitepress-logo-large.svg 18 | alt: create-vite-lib-starter 19 | 20 | features: 21 | - title: Feature A 22 | details: Lorem ipsum dolor sit amet, consectetur adipiscing elit 23 | - title: Feature B 24 | details: Lorem ipsum dolor sit amet, consectetur adipiscing elit 25 | - title: Feature C 26 | details: Lorem ipsum dolor sit amet, consectetur adipiscing elit 27 | --- 28 | 29 | -------------------------------------------------------------------------------- /examples/config/vite.view.6.mts: -------------------------------------------------------------------------------- 1 | import vue from '@vitejs/plugin-vue'; 2 | import { defineConfig, Plugin } from 'vite'; 3 | import vitePluginExternal from 'vite-plugin-external'; 4 | import { view } from 'vite-plugin-view'; 5 | 6 | // https://vitejs.dev/config/ 7 | export default defineConfig({ 8 | plugins: [ 9 | vitePluginExternal({ 10 | logLevel: 'TRACE', 11 | externals: { 12 | vue: 'Vue' 13 | } 14 | }), 15 | vue() as Plugin, 16 | view({ 17 | engine: 'pug', 18 | logLevel: 'TRACE', 19 | engineOptions: { 20 | title: 'Vite + Vue' 21 | } 22 | }) as Plugin 23 | ], 24 | server: { 25 | open: true 26 | }, 27 | build: { 28 | minify: false, 29 | outDir: 'dist/view/6', 30 | rollupOptions: { 31 | output: { 32 | format: 'iife' 33 | } 34 | } 35 | } 36 | }); 37 | -------------------------------------------------------------------------------- /.husky/_/husky.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | if [ -z "$husky_skip_init" ]; then 3 | debug () { 4 | if [ "$HUSKY_DEBUG" = "1" ]; then 5 | echo "husky (debug) - $1" 6 | fi 7 | } 8 | 9 | readonly hook_name="$(basename -- "$0")" 10 | debug "starting $hook_name..." 11 | 12 | if [ "$HUSKY" = "0" ]; then 13 | debug "HUSKY env variable is set to 0, skipping hook" 14 | exit 0 15 | fi 16 | 17 | if [ -f ~/.huskyrc ]; then 18 | debug "sourcing ~/.huskyrc" 19 | . ~/.huskyrc 20 | fi 21 | 22 | readonly husky_skip_init=1 23 | export husky_skip_init 24 | sh -e "$0" "$@" 25 | exitCode="$?" 26 | 27 | if [ $exitCode != 0 ]; then 28 | echo "husky - $hook_name hook exited with code $exitCode (error)" 29 | fi 30 | 31 | if [ $exitCode = 127 ]; then 32 | echo "husky - command not found in PATH=$PATH" 33 | fi 34 | 35 | exit $exitCode 36 | fi 37 | -------------------------------------------------------------------------------- /docs/en/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | # https://vitepress.dev/reference/default-theme-home-page 3 | layout: home 4 | 5 | hero: 6 | name: vite-plugins 7 | text: A collection of custom plugins designed to enhance the functionality of the Vite build tool. 8 | tagline: Come and give it a try! 9 | actions: 10 | - theme: brand 11 | text: Introduction 12 | link: /guide/introduction 13 | # - theme: alt 14 | # text: API Examples 15 | # link: /api-examples 16 | image: 17 | src: https://vitepress.dev/vitepress-logo-large.svg 18 | alt: vite-plugins 19 | 20 | # features: 21 | # - title: Feature A 22 | # details: Lorem ipsum dolor sit amet, consectetur adipiscing elit 23 | # - title: Feature B 24 | # details: Lorem ipsum dolor sit amet, consectetur adipiscing elit 25 | # - title: Feature C 26 | # details: Lorem ipsum dolor sit amet, consectetur adipiscing elit 27 | --- 28 | 29 | -------------------------------------------------------------------------------- /docs/zh/plugins/vite-plugin-mock-data/quick-start.md: -------------------------------------------------------------------------------- 1 | # vite-plugin-mock-data 2 | 3 | [![npm package](https://nodei.co/npm/vite-plugin-mock-data.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/vite-plugin-mock-data) 4 | 5 | > 提供了一种简单的方式来模拟数据。 6 | 7 | [![NPM version](https://img.shields.io/npm/v/vite-plugin-mock-data.svg?style=flat)](https://npmjs.org/package/vite-plugin-mock-data) 8 | [![NPM Downloads](https://img.shields.io/npm/dm/vite-plugin-mock-data.svg?style=flat)](https://npmjs.org/package/vite-plugin-mock-data) 9 | [![Node version](https://img.shields.io/node/v/vite-plugin-mock-data.svg?style=flat)](https://npmjs.org/package/vite-plugin-mock-data) 10 | 11 | ## 安装 12 | 13 | ::: code-group 14 | 15 | ```bash [npm] 16 | npm add vite-plugin-mock-data 17 | ``` 18 | ```bash [pnpm] 19 | pnpm add vite-plugin-mock-data 20 | ``` 21 | ```bash [yarn] 22 | yarn add vite-plugin-mock-data 23 | ``` 24 | 25 | ::: 26 | -------------------------------------------------------------------------------- /examples/vite3-demo/index.pug: -------------------------------------------------------------------------------- 1 | doctype html 2 | html(lang='en') 3 | head 4 | meta(charset='UTF-8') 5 | meta(content='width=device-width, initial-scale=1.0' name='viewport') 6 | title= title 7 | //- link(href='./index.css' rel='stylesheet') 8 | body 9 | #root 10 | if reactVersion === '16.x' 11 | script(src='//g.alicdn.com/linkdesign/lib/1.0.1/??babel-polyfill.js,~react.js') 12 | script(src='./r/index.jsx' type='module') 13 | if reactVersion === '18.x' 14 | script(src='//unpkg.com/react@18.3.1/umd/react.production.min.js') 15 | script(src='//unpkg.com/react-dom@18.3.1/umd/react-dom.production.min.js') 16 | script(src='./r/index2.jsx' type='module') 17 | if reactFormat === 'esm' 18 | script(src='./r/index2.jsx' type='module') 19 | if vueVersion === '3.x' 20 | script(src='//unpkg.com/vue@3.5.13/dist/vue.runtime.global.js') 21 | script(src='./v/main.ts' type='module') -------------------------------------------------------------------------------- /examples/vite4-demo/index.pug: -------------------------------------------------------------------------------- 1 | doctype html 2 | html(lang='en') 3 | head 4 | meta(charset='UTF-8') 5 | meta(content='width=device-width, initial-scale=1.0' name='viewport') 6 | title= title 7 | //- link(href='./index.css' rel='stylesheet') 8 | body 9 | #root 10 | if reactVersion === '16.x' 11 | script(src='//g.alicdn.com/linkdesign/lib/1.0.1/??babel-polyfill.js,~react.js') 12 | script(src='./r/index.jsx' type='module') 13 | if reactVersion === '18.x' 14 | script(src='//unpkg.com/react@18.3.1/umd/react.production.min.js') 15 | script(src='//unpkg.com/react-dom@18.3.1/umd/react-dom.production.min.js') 16 | script(src='./r/index2.jsx' type='module') 17 | if reactFormat === 'esm' 18 | script(src='./r/index2.jsx' type='module') 19 | if vueVersion === '3.x' 20 | script(src='//unpkg.com/vue@3.5.13/dist/vue.runtime.global.js') 21 | script(src='./v/main.ts' type='module') -------------------------------------------------------------------------------- /examples/vite5-demo/index.pug: -------------------------------------------------------------------------------- 1 | doctype html 2 | html(lang='en') 3 | head 4 | meta(charset='UTF-8') 5 | meta(content='width=device-width, initial-scale=1.0' name='viewport') 6 | title= title 7 | //- link(href='./index.css' rel='stylesheet') 8 | body 9 | #root 10 | if reactVersion === '16.x' 11 | script(src='//g.alicdn.com/linkdesign/lib/1.0.1/??babel-polyfill.js,~react.js') 12 | script(src='./r/index.jsx' type='module') 13 | if reactVersion === '18.x' 14 | script(src='//unpkg.com/react@18.3.1/umd/react.production.min.js') 15 | script(src='//unpkg.com/react-dom@18.3.1/umd/react-dom.production.min.js') 16 | script(src='./r/index2.jsx' type='module') 17 | if reactFormat === 'esm' 18 | script(src='./r/index2.jsx' type='module') 19 | if vueVersion === '3.x' 20 | script(src='//unpkg.com/vue@3.5.13/dist/vue.runtime.global.js') 21 | script(src='./v/main.ts' type='module') -------------------------------------------------------------------------------- /examples/vite6-demo/index.pug: -------------------------------------------------------------------------------- 1 | doctype html 2 | html(lang='en') 3 | head 4 | meta(charset='UTF-8') 5 | meta(content='width=device-width, initial-scale=1.0' name='viewport') 6 | title= title 7 | //- link(href='./index.css' rel='stylesheet') 8 | body 9 | #root 10 | if reactVersion === '16.x' 11 | script(src='//g.alicdn.com/linkdesign/lib/1.0.1/??babel-polyfill.js,~react.js') 12 | script(src='./r/index.jsx' type='module') 13 | if reactVersion === '18.x' 14 | script(src='//unpkg.com/react@18.3.1/umd/react.production.min.js') 15 | script(src='//unpkg.com/react-dom@18.3.1/umd/react-dom.production.min.js') 16 | script(src='./r/index2.jsx' type='module') 17 | if reactFormat === 'esm' 18 | script(src='./r/index2.jsx' type='module') 19 | if vueVersion === '3.x' 20 | script(src='//unpkg.com/vue@3.5.13/dist/vue.runtime.global.js') 21 | script(src='./v/main.ts' type='module') -------------------------------------------------------------------------------- /packages/vite-plugin-cp/src/util.ts: -------------------------------------------------------------------------------- 1 | import { readFile } from 'node:fs/promises'; 2 | import { inspect } from 'node:util'; 3 | 4 | import { copy, outputFile } from 'fs-extra'; 5 | 6 | import { TransformFile } from './typings'; 7 | 8 | export function stringify(value: any): string { 9 | return inspect(value, { breakLength: Infinity }); 10 | } 11 | 12 | export function changeName(name: string, rename?: string | ((str: string) => string)) { 13 | if (typeof rename === 'function') { 14 | return rename(name) || name; 15 | } 16 | return rename || name; 17 | } 18 | 19 | export function makeCopy(transform?: TransformFile) { 20 | return typeof transform === 'function' 21 | ? function (from: string, to: string) { 22 | return readFile(from) 23 | .then((buf: Buffer) => transform(buf, from)) 24 | .then((data: string | Buffer) => { 25 | return outputFile(to, data as any); 26 | }); 27 | } 28 | : copy; 29 | } 30 | -------------------------------------------------------------------------------- /docs/en/plugins/vite-plugin-mock-data/quick-start.md: -------------------------------------------------------------------------------- 1 | # vite-plugin-mock-data 2 | 3 | [![npm package](https://nodei.co/npm/vite-plugin-mock-data.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/vite-plugin-mock-data) 4 | 5 | > Provides a simple way to mock data. 6 | 7 | [![NPM version](https://img.shields.io/npm/v/vite-plugin-mock-data.svg?style=flat)](https://npmjs.org/package/vite-plugin-mock-data) 8 | [![NPM Downloads](https://img.shields.io/npm/dm/vite-plugin-mock-data.svg?style=flat)](https://npmjs.org/package/vite-plugin-mock-data) 9 | [![Node version](https://img.shields.io/node/v/vite-plugin-mock-data.svg?style=flat)](https://npmjs.org/package/vite-plugin-mock-data) 10 | 11 | ## Installation 12 | 13 | ::: code-group 14 | 15 | ```bash [npm] 16 | npm add vite-plugin-mock-data 17 | ``` 18 | ```bash [pnpm] 19 | pnpm add vite-plugin-mock-data 20 | ``` 21 | ```bash [yarn] 22 | yarn add vite-plugin-mock-data 23 | ``` 24 | 25 | ::: 26 | -------------------------------------------------------------------------------- /examples/config/vite.external.11.mts: -------------------------------------------------------------------------------- 1 | import vue from '@vitejs/plugin-vue'; 2 | import type { Plugin } from 'vite'; 3 | import { defineConfig } from 'vite'; 4 | import vitePluginExternal from 'vite-plugin-external'; 5 | import { view } from 'vite-plugin-view'; 6 | 7 | // https://vitejs.dev/config/ 8 | export default defineConfig({ 9 | plugins: [ 10 | vue() as Plugin, 11 | vitePluginExternal({ 12 | logLevel: 'TRACE', 13 | externals: { 14 | vue: 'Vue' 15 | } 16 | }) as unknown as Plugin, 17 | view({ 18 | engine: 'pug', 19 | logLevel: 'TRACE', 20 | engineOptions: { 21 | title: 'Vite + Vue + Pug', 22 | vueVersion: '3.x' 23 | } 24 | }) as Plugin 25 | ], 26 | server: { 27 | open: true 28 | }, 29 | build: { 30 | minify: false, 31 | outDir: 'dist/view/6', 32 | rollupOptions: { 33 | output: { 34 | format: 'iife' 35 | } 36 | } 37 | } 38 | }); 39 | -------------------------------------------------------------------------------- /packages/vp-runtime-helper/src/logger.ts: -------------------------------------------------------------------------------- 1 | import { inspect } from 'node:util'; 2 | 3 | import { Level, LogEvent, LogFactory, PatternLayout, TPatternConverter } from 'base-log-factory'; 4 | import { DebugAppender } from 'blf-debug-appender'; 5 | 6 | function createConverter(specifier: string): TPatternConverter | undefined { 7 | if (specifier === 'm') { 8 | return (event: LogEvent): string => { 9 | return event.message.map((msg) => { 10 | switch (typeof msg) { 11 | case 'object': 12 | return inspect(msg); 13 | case 'symbol': 14 | return msg.toString(); 15 | default: 16 | return msg; 17 | } 18 | }).join(' '); 19 | }; 20 | } 21 | } 22 | 23 | export const logFactory = new LogFactory({ 24 | level: Level.WARN, 25 | appenders: [ 26 | new DebugAppender({ 27 | layout: new PatternLayout( 28 | '%d{HH:mm:ss} [%p] - %m', 29 | createConverter 30 | ) 31 | }) 32 | ] 33 | }); 34 | -------------------------------------------------------------------------------- /examples/config/vite.view.5.mts: -------------------------------------------------------------------------------- 1 | import react from '@vitejs/plugin-react'; 2 | import { defineConfig, Plugin } from 'vite'; 3 | import vitePluginExternal from 'vite-plugin-external'; 4 | import { view } from 'vite-plugin-view'; 5 | 6 | // https://vitejs.dev/config/ 7 | export default defineConfig({ 8 | plugins: [ 9 | vitePluginExternal({ 10 | logLevel: 'TRACE', 11 | externals: { 12 | react: 'React', 13 | 'react-dom/client': 'ReactDOM' 14 | } 15 | }), 16 | react({ 17 | jsxRuntime: 'classic' 18 | }) as unknown as Plugin, 19 | view({ 20 | entry: 'index.ejs', 21 | engine: 'ejs', 22 | logLevel: 'TRACE', 23 | engineOptions: { 24 | title: 'Vite + React' 25 | } 26 | }) as Plugin 27 | ], 28 | server: { 29 | open: true 30 | }, 31 | build: { 32 | minify: false, 33 | outDir: 'dist/view/5', 34 | rollupOptions: { 35 | output: { 36 | format: 'iife' 37 | } 38 | } 39 | } 40 | }); 41 | -------------------------------------------------------------------------------- /docs/zh/plugins/vite-plugin-hook-use/usage.md: -------------------------------------------------------------------------------- 1 | # 使用示例 2 | 3 | 假设你有以下文件结构: 4 | 5 | ``` 6 | src/ 7 | |- index.js 8 | ``` 9 | 10 | 配置如下: 11 | 12 | ```typescript 13 | import { defineConfig } from 'vite'; 14 | import vitePluginHookUse from 'vite-plugin-hook-use'; 15 | 16 | export default defineConfig({ 17 | plugins: [ 18 | vitePluginHookUse() 19 | ] 20 | }); 21 | ``` 22 | 23 | ```bash 24 | vite build 25 | ``` 26 | 27 | 将会在控制台打印出以下内容,数字表示调用次数 28 | 29 | ```bash 30 | ┌ === Start === 31 | │ 32 | ◇ config(1) 33 | │ 34 | ◇ configResolved(1) 35 | │ 36 | ◇ options(1) 37 | │ 38 | ◇ buildStart(1) 39 | │ 40 | ◇ load(1) 41 | │ 42 | ◇ transform(1) 43 | │ 44 | ◇ moduleParsed(1) 45 | │ 46 | ◇ buildEnd(1) 47 | │ 48 | ◇ outputOptions(1) 49 | │ 50 | ◇ renderStart(1) 51 | │ 52 | ◇ banner(1) 53 | │ 54 | ◇ footer(1) 55 | │ 56 | ◇ intro(1) 57 | │ 58 | ◇ outro(1) 59 | │ 60 | ◇ renderChunk(1) 61 | │ 62 | ◇ generateBundle(1) 63 | │ 64 | ◇ writeBundle(1) 65 | │ 66 | ◇ closeBundle(1) 67 | │ 68 | └ === End === 69 | ``` 70 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/bin/index.mjs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import { basename, dirname, resolve } from 'node:path'; 4 | import { fileURLToPath } from 'node:url'; 5 | 6 | import { generateStarter } from 'cs-runtime-helper'; 7 | import { ensureDir } from 'fs-extra'; 8 | 9 | const __filename = fileURLToPath(import.meta.url); 10 | const __dirname = dirname(__filename); 11 | 12 | const cwd = resolve('.'); 13 | const targetDir = resolve(process.argv[2] || '.'); 14 | 15 | async function run() { 16 | if (targetDir !== cwd) { 17 | await ensureDir(targetDir); 18 | } 19 | 20 | const templateDir = resolve(__dirname, '..'); 21 | const packageName = basename(targetDir); 22 | 23 | const startTime = Date.now(); 24 | await generateStarter(templateDir, targetDir, { 25 | name: packageName, 26 | version: '1.0.0', 27 | files: [ 28 | 'dist' 29 | ], 30 | dependencies: {} 31 | }); 32 | console.info(`Generated '${packageName}' in ${(Date.now() - startTime)} ms.`); 33 | } 34 | 35 | run(); 36 | -------------------------------------------------------------------------------- /docs/zh/plugins/vite-plugin-separate-importer/quick-start.md: -------------------------------------------------------------------------------- 1 | # vite-plugin-separate-importer 2 | 3 | [![npm package](https://nodei.co/npm/vite-plugin-separate-importer.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/vite-plugin-separate-importer) 4 | 5 | > 将原来从一个源模块批量导入内容变成分批从源模块下导入单个文件。 6 | 7 | [![NPM version](https://img.shields.io/npm/v/vite-plugin-separate-importer.svg?style=flat)](https://npmjs.org/package/vite-plugin-separate-importer) 8 | [![NPM Downloads](https://img.shields.io/npm/dm/vite-plugin-separate-importer.svg?style=flat)](https://npmjs.org/package/vite-plugin-separate-importer) 9 | [![Node version](https://img.shields.io/node/v/vite-plugin-separate-importer.svg?style=flat)](https://npmjs.org/package/vite-plugin-separate-importer) 10 | 11 | ## 安装 12 | 13 | ::: code-group 14 | 15 | ```bash [npm] 16 | npm add vite-plugin-separate-importer 17 | ``` 18 | ```bash [pnpm] 19 | pnpm add vite-plugin-separate-importer 20 | ``` 21 | ```bash [yarn] 22 | yarn add vite-plugin-separate-importer 23 | ``` 24 | 25 | ::: 26 | -------------------------------------------------------------------------------- /examples/config/vite.external.5.mts: -------------------------------------------------------------------------------- 1 | import react from '@vitejs/plugin-react'; 2 | import type { Plugin } from 'vite'; 3 | import { defineConfig } from 'vite'; 4 | import vitePluginExternal from 'vite-plugin-external'; 5 | import { view } from 'vite-plugin-view'; 6 | 7 | // https://vitejs.dev/config/ 8 | export default defineConfig({ 9 | plugins: [ 10 | react({ 11 | jsxRuntime: 'classic' 12 | }) as unknown as Plugin, 13 | vitePluginExternal({ 14 | logLevel: 'TRACE', 15 | externals: { 16 | react: 'React', 17 | 'react-dom/client': 'ReactDOM' 18 | } 19 | }) as unknown as Plugin, 20 | view({ 21 | engine: 'pug', 22 | engineOptions: { 23 | title: 'Vite + React + Pug', 24 | reactVersion: '18.x' 25 | } 26 | }) as unknown as Plugin 27 | ], 28 | server: { 29 | open: true 30 | }, 31 | build: { 32 | minify: false, 33 | outDir: 'dist/external/5', 34 | rollupOptions: { 35 | output: { 36 | format: 'iife' 37 | } 38 | } 39 | } 40 | }); 41 | -------------------------------------------------------------------------------- /docs/zh/guide/introduction.md: -------------------------------------------------------------------------------- 1 | # vite-plugins 2 | 3 | > `vite-plugins` 是一个包含多个自定义插件的集合,用于增强 Vite 构建工具的功能。 4 | 5 | ## 插件列表 6 | 7 | * [vite-plugin-combine](/zh/plugins/vite-plugin-combine/quick-start) - 将多个模块文件合并成一个目标文件。它支持命名导出、默认导出、自动导出和无导出四种模式,并可以根据配置自动生成相应的导入语句。 8 | 9 | * [vite-plugin-cp](/zh/plugins/vite-plugin-cp/quick-start) - 一个用于复制文件/目录,并支持灵活转换文件内容、保留或扁平化目录结构、自定义文件重命名等的Vite插件。 10 | 11 | * [vite-plugin-external](/zh/plugins/vite-plugin-external/quick-start) - 从运行时代码和构建后的 bundles 中排除指定的模块依赖项。 12 | 13 | * [vite-plugin-hook-use](/zh/plugins/vite-plugin-hook-use/quick-start) - 显示 `vite` 调用其钩子函数的序列和频率 14 | 15 | * [vite-plugin-include-css](/zh/plugins/vite-plugin-include-css/quick-start) - 当启用 `cssCodeSplit: false` 时,将所有CSS打包到单个JavaScript文件中。 16 | 17 | * [vite-plugin-mock-data](/zh/plugins/vite-plugin-mock-data/quick-start) - 提供了一种简单的方式来模拟数据。 18 | 19 | * [vite-plugin-separate-importer](/zh/plugins/vite-plugin-separate-importer/quick-start) - 将原来从一个源模块批量导入内容变成分批从源模块下导入单个文件。 20 | 21 | * [vite-plugin-view](/plugins/vite-plugin-view/quick-start) - 使用自定义模板引擎动态渲染页面,替代静态的 `.html` 入口文件。 -------------------------------------------------------------------------------- /examples/config/vite.external.6.mts: -------------------------------------------------------------------------------- 1 | import react from '@vitejs/plugin-react'; 2 | import type { Plugin } from 'vite'; 3 | import { defineConfig } from 'vite'; 4 | import vitePluginExternal from 'vite-plugin-external'; 5 | import { view } from 'vite-plugin-view'; 6 | 7 | // https://vitejs.dev/config/ 8 | export default defineConfig({ 9 | plugins: [ 10 | react({ 11 | jsxRuntime: 'classic' 12 | }) as unknown as Plugin, 13 | vitePluginExternal({ 14 | interop: 'auto', 15 | logLevel: 'TRACE', 16 | externals: { 17 | react: 'React', 18 | 'react-dom/client': 'ReactDOM' 19 | } 20 | }) as unknown as Plugin, 21 | view({ 22 | engine: 'pug', 23 | engineOptions: { 24 | title: 'Vite + React + Pug', 25 | reactVersion: '18.x' 26 | } 27 | }) as unknown as Plugin 28 | ], 29 | server: { 30 | open: true 31 | }, 32 | build: { 33 | minify: false, 34 | outDir: 'dist/external/6', 35 | rollupOptions: { 36 | output: { 37 | format: 'iife' 38 | } 39 | } 40 | } 41 | }); 42 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/docs/.vitepress/config/en.mts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vitepress' 2 | import { generateAPISidebar } from './shared.mjs' 3 | 4 | // https://vitepress.dev/reference/site-config 5 | export const en = defineConfig({ 6 | description: "Here is description.", 7 | lang: 'en-US', 8 | themeConfig: { 9 | // https://vitepress.dev/reference/default-theme-config 10 | nav: [ 11 | { 12 | text: 'Guide', 13 | link: '/guide/introduction', 14 | activeMatch: '/guide/' 15 | }, 16 | { 17 | text: 'API', 18 | link: '/api/entry', 19 | activeMatch: '/api/' 20 | } 21 | ], 22 | 23 | sidebar: { 24 | '/guide/': { 25 | base: '/guide/', 26 | items: [ 27 | { text: 'Introduction', link: 'introduction' } 28 | ] 29 | }, 30 | '/api/': { 31 | base: '/api/', 32 | items: generateAPISidebar('../../en/api') 33 | } 34 | }, 35 | 36 | socialLinks: [ 37 | { icon: 'github', link: 'https://github.com/fengxinming/vite-plugins' } 38 | ] 39 | } 40 | }) -------------------------------------------------------------------------------- /examples/config/vite.include-css.1.mts: -------------------------------------------------------------------------------- 1 | import type { Plugin } from 'vite'; 2 | import { defineConfig } from 'vite'; 3 | import vitePluginExternal from 'vite-plugin-external'; 4 | import vitePluginIncludeCss from 'vite-plugin-include-css'; 5 | import { view } from 'vite-plugin-view'; 6 | 7 | // https://vitejs.dev/config/ 8 | export default defineConfig({ 9 | plugins: [ 10 | vitePluginExternal({ 11 | externals: { 12 | react: '$linkdesign.React', 13 | 'react-dom': '$linkdesign.ReactDOM', 14 | 'prop-types': '$linkdesign.PropTypes' 15 | } 16 | }) as unknown as Plugin, 17 | vitePluginIncludeCss() as unknown as Plugin, 18 | view({ 19 | engine: 'pug', 20 | engineOptions: { 21 | title: 'Vite + React + Pug', 22 | reactVersion: '16.x' 23 | } 24 | }) as unknown as Plugin 25 | ], 26 | server: { 27 | open: true 28 | }, 29 | build: { 30 | outDir: 'dist/include-css', 31 | cssCodeSplit: false, 32 | minify: false, 33 | rollupOptions: { 34 | output: { 35 | format: 'iife' 36 | } 37 | } 38 | } 39 | }); 40 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/docs/.vitepress/config/zh.mts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vitepress' 2 | import { generateAPISidebar } from './shared.mjs' 3 | 4 | // https://vitepress.dev/reference/site-config 5 | export const zh = defineConfig({ 6 | description: "这里是描述。", 7 | lang: 'zh-CN', 8 | themeConfig: { 9 | // https://vitepress.dev/reference/default-theme-config 10 | nav: [ 11 | { 12 | text: '指引', 13 | link: '/zh/guide/introduction', 14 | activeMatch: '/zh/guide/' 15 | }, 16 | { 17 | text: 'APi', 18 | link: '/zh/api/entry', 19 | activeMatch: '/zh/api/' 20 | } 21 | ], 22 | 23 | sidebar: { 24 | '/zh/guide/': { 25 | base: '/zh/guide/', 26 | items: [ 27 | { text: '介绍', link: 'introduction' }, 28 | ] 29 | }, 30 | '/zh/api/': { 31 | base: '/zh/api/', 32 | items: generateAPISidebar('../../zh/api') 33 | } 34 | }, 35 | 36 | socialLinks: [ 37 | { icon: 'github', link: 'https://github.com/fengxinming/vite-plugins' } 38 | ] 39 | } 40 | }) 41 | -------------------------------------------------------------------------------- /docs/en/plugins/vite-plugin-separate-importer/quick-start.md: -------------------------------------------------------------------------------- 1 | # vite-plugin-separate-importer 2 | 3 | [![npm package](https://nodei.co/npm/vite-plugin-separate-importer.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/vite-plugin-separate-importer) 4 | 5 | > Converts batch imports from a source module into separate imports from individual files under the source module. 6 | 7 | [![NPM version](https://img.shields.io/npm/v/vite-plugin-separate-importer.svg?style=flat)](https://npmjs.org/package/vite-plugin-separate-importer) 8 | [![NPM Downloads](https://img.shields.io/npm/dm/vite-plugin-separate-importer.svg?style=flat)](https://npmjs.org/package/vite-plugin-separate-importer) 9 | [![Node version](https://img.shields.io/node/v/vite-plugin-separate-importer.svg?style=flat)](https://npmjs.org/package/vite-plugin-separate-importer) 10 | 11 | ## Installation 12 | 13 | ::: code-group 14 | 15 | ```bash [npm] 16 | npm add vite-plugin-separate-importer 17 | ``` 18 | ```bash [pnpm] 19 | pnpm add vite-plugin-separate-importer 20 | ``` 21 | ```bash [yarn] 22 | yarn add vite-plugin-separate-importer 23 | ``` 24 | 25 | ::: -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Jesse Feng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/config/vite.mock-data.1.mts: -------------------------------------------------------------------------------- 1 | import type { Plugin } from 'vite'; 2 | import { defineConfig } from 'vite'; 3 | import pluginExternal from 'vite-plugin-external'; 4 | import pluginMockData from 'vite-plugin-mock-data'; 5 | import { view } from 'vite-plugin-view'; 6 | 7 | // https://vitejs.dev/config/ 8 | export default defineConfig({ 9 | plugins: [ 10 | pluginExternal({ 11 | externals: { 12 | react: '$linkdesign.React', 13 | 'react-dom': '$linkdesign.ReactDOM', 14 | 'prop-types': '$linkdesign.PropTypes' 15 | } 16 | }) as unknown as Plugin, 17 | pluginMockData({ 18 | logLevel: 'TRACE', 19 | routes: './mock' 20 | }) as unknown as Plugin, 21 | view({ 22 | engine: 'pug', 23 | engineOptions: { 24 | title: 'Vite + React + Pug', 25 | reactVersion: '16.x' 26 | } 27 | }) as unknown as Plugin 28 | ], 29 | server: { 30 | open: true 31 | }, 32 | build: { 33 | outDir: 'dist/mock-data/1', 34 | minify: false, 35 | rollupOptions: { 36 | 37 | output: { 38 | format: 'iife' 39 | } 40 | } 41 | } 42 | }); 43 | -------------------------------------------------------------------------------- /examples/config/vite.view.4.mts: -------------------------------------------------------------------------------- 1 | import react from '@vitejs/plugin-react'; 2 | import Handlebars from 'handlebars'; 3 | import { defineConfig, Plugin } from 'vite'; 4 | import vitePluginExternal from 'vite-plugin-external'; 5 | import { view } from 'vite-plugin-view'; 6 | 7 | Handlebars.registerHelper('stringify', (obj) => { 8 | return JSON.stringify(obj, null, 2); 9 | }); 10 | 11 | // https://vitejs.dev/config/ 12 | export default defineConfig({ 13 | plugins: [ 14 | react({ 15 | jsxRuntime: 'classic' 16 | }) as unknown as Plugin, 17 | vitePluginExternal({ 18 | logLevel: 'TRACE', 19 | externals: { 20 | react: 'React', 21 | 'react-dom/client': 'ReactDOM' 22 | } 23 | }) as unknown as Plugin, 24 | view({ 25 | entry: 'index.hbs', 26 | engine: 'handlebars', 27 | extension: '.hbs', 28 | logLevel: 'TRACE' 29 | }) as Plugin 30 | ], 31 | server: { 32 | open: true 33 | }, 34 | build: { 35 | minify: false, 36 | outDir: 'dist/view/4', 37 | rollupOptions: { 38 | output: { 39 | format: 'iife' 40 | } 41 | } 42 | } 43 | }); 44 | -------------------------------------------------------------------------------- /packages/vp-runtime-helper/src/index.ts: -------------------------------------------------------------------------------- 1 | import { isAbsolute, join } from 'node:path'; 2 | 3 | import figlet from 'figlet'; 4 | import { normalizePath } from 'vite'; 5 | 6 | const escapeRegexRE = /[-/\\^$*+?.()|[\]{}]/g; 7 | export function escapeRegex(str: string): string { 8 | return str.replace(escapeRegexRE, '\\$&'); 9 | } 10 | 11 | 12 | export function banner(text: string, opts?: any): void { 13 | // eslint-disable-next-line no-console 14 | console.log(figlet.textSync(text, opts)); 15 | } 16 | 17 | export function toAbsolutePath(pth: string, cwd: string): string { 18 | if (!isAbsolute(pth)) { 19 | pth = join(cwd, pth); 20 | } 21 | return normalizePath(pth); 22 | } 23 | 24 | export function sleep(ms: number): Promise { 25 | return new Promise((resolve) => { 26 | setTimeout(resolve, ms); 27 | }); 28 | } 29 | 30 | export * from './colorful'; 31 | export * from './depsCache'; 32 | export * from './devServer'; 33 | export * from './getValue'; 34 | export * from './hash'; 35 | export * from './logger'; 36 | export * from './time'; 37 | export * from './version'; 38 | export type { LogLevel } from 'base-log-factory'; 39 | -------------------------------------------------------------------------------- /examples/config/vite.external.2.mts: -------------------------------------------------------------------------------- 1 | import react from '@vitejs/plugin-react'; 2 | import type { Plugin } from 'vite'; 3 | import { defineConfig } from 'vite'; 4 | import vitePluginExternal from 'vite-plugin-external'; 5 | import { view } from 'vite-plugin-view'; 6 | 7 | // https://vitejs.dev/config/ 8 | export default defineConfig({ 9 | plugins: [ 10 | react({ 11 | jsxRuntime: 'classic' 12 | }) as unknown as Plugin, 13 | vitePluginExternal({ 14 | interop: 'auto', 15 | logLevel: 'TRACE', 16 | externals: { 17 | react: '$linkdesign.React', 18 | 'react-dom': '$linkdesign.ReactDOM', 19 | 'prop-types': '$linkdesign.PropTypes' 20 | } 21 | }) as unknown as Plugin, 22 | view({ 23 | engine: 'pug', 24 | engineOptions: { 25 | title: 'Vite + React + Pug', 26 | reactVersion: '16.x' 27 | } 28 | }) as unknown as Plugin 29 | ], 30 | server: { 31 | open: true 32 | }, 33 | build: { 34 | minify: false, 35 | outDir: 'dist/external/2', 36 | rollupOptions: { 37 | output: { 38 | format: 'iife' 39 | } 40 | } 41 | } 42 | }); 43 | -------------------------------------------------------------------------------- /examples/config/vite.external.1.mts: -------------------------------------------------------------------------------- 1 | import react from '@vitejs/plugin-react'; 2 | import type { Plugin } from 'vite'; 3 | import { defineConfig } from 'vite'; 4 | import vitePluginExternal from 'vite-plugin-external'; 5 | import { view } from 'vite-plugin-view'; 6 | 7 | // https://vitejs.dev/config/ 8 | export default defineConfig({ 9 | plugins: [ 10 | react({ 11 | jsxRuntime: 'classic' 12 | }) as unknown as Plugin, 13 | vitePluginExternal({ 14 | logLevel: 'TRACE', 15 | externals: { 16 | react: '$linkdesign.React', 17 | 'react-dom': '$linkdesign.ReactDOM', 18 | 'prop-types': '$linkdesign.PropTypes' 19 | } 20 | }) as unknown as Plugin, 21 | view({ 22 | engine: 'pug', 23 | engineOptions: { 24 | title: 'Vite + React + Pug', 25 | reactVersion: '16.x' 26 | } 27 | }) as unknown as Plugin 28 | ], 29 | server: { 30 | open: true 31 | }, 32 | build: { 33 | minify: false, 34 | // cssCodeSplit: false, 35 | outDir: 'dist/external/1', 36 | rollupOptions: { 37 | output: { 38 | format: 'iife' 39 | } 40 | } 41 | } 42 | }); 43 | -------------------------------------------------------------------------------- /examples/config/vite.external.8.mts: -------------------------------------------------------------------------------- 1 | import react from '@vitejs/plugin-react'; 2 | import externalGlobals from 'rollup-plugin-external-globals'; 3 | import type { Plugin } from 'vite'; 4 | import { defineConfig } from 'vite'; 5 | import vitePluginExternal from 'vite-plugin-external'; 6 | import { view } from 'vite-plugin-view'; 7 | 8 | // https://vitejs.dev/config/ 9 | export default defineConfig({ 10 | plugins: [ 11 | react({ 12 | jsxRuntime: 'classic' 13 | }) as unknown as Plugin, 14 | vitePluginExternal({ 15 | externalGlobals, 16 | logLevel: 'TRACE', 17 | externals: { 18 | react: 'React', 19 | 'react-dom/client': 'ReactDOM' 20 | } 21 | }) as unknown as Plugin, 22 | view({ 23 | engine: 'pug', 24 | engineOptions: { 25 | title: 'Vite + React + Pug', 26 | reactVersion: '18.x' 27 | } 28 | }) as unknown as Plugin 29 | ], 30 | server: { 31 | open: true 32 | }, 33 | build: { 34 | minify: false, 35 | outDir: 'dist/external/8', 36 | rollupOptions: { 37 | output: { 38 | format: 'iife' 39 | } 40 | } 41 | } 42 | }); 43 | -------------------------------------------------------------------------------- /packages/cs-runtime-helper/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Jesse Feng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/vite-plugin-cp/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Jesse Feng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/vite-plugin-view/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Jesse Feng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/vp-runtime-helper/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Jesse Feng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/vite-plugin-build-chunk/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Jesse Feng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/vite-plugin-combine/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Jesse Feng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/vite-plugin-external/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Jesse Feng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/vite-plugin-hook-use/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Jesse Feng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/vite-plugin-include-css/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Jesse Feng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/vite-plugin-mock-data/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Jesse Feng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/docs/.vitepress/cache/deps/_metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "hash": "22d93a89", 3 | "configHash": "7e6442d6", 4 | "lockfileHash": "e3b0c442", 5 | "browserHash": "d7375c65", 6 | "optimized": { 7 | "vue": { 8 | "src": "../../../../../../node_modules/.pnpm/vue@3.5.13_typescript@5.8.3/node_modules/vue/dist/vue.runtime.esm-bundler.js", 9 | "file": "vue.js", 10 | "fileHash": "fd3658bb", 11 | "needsInterop": false 12 | }, 13 | "vitepress > @vue/devtools-api": { 14 | "src": "../../../../../../node_modules/.pnpm/@vue+devtools-api@7.7.2/node_modules/@vue/devtools-api/dist/index.js", 15 | "file": "vitepress___@vue_devtools-api.js", 16 | "fileHash": "5b513fd6", 17 | "needsInterop": false 18 | }, 19 | "vitepress > @vueuse/core": { 20 | "src": "../../../../../../node_modules/.pnpm/@vueuse+core@12.8.2_typescript@5.8.3/node_modules/@vueuse/core/index.mjs", 21 | "file": "vitepress___@vueuse_core.js", 22 | "fileHash": "fc9dc9b2", 23 | "needsInterop": false 24 | } 25 | }, 26 | "chunks": { 27 | "chunk-VYSRTDRI": { 28 | "file": "chunk-VYSRTDRI.js" 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/test/index.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, test, vi } from 'vitest'; 2 | 3 | import { isNil, noop } from '../src/index'; 4 | 5 | describe('Utils Functions', () => { 6 | describe('isNil', () => { 7 | test('returns true for null', () => { 8 | expect(isNil(null)).toBe(true); 9 | }); 10 | 11 | test('returns true for undefined', () => { 12 | expect(isNil(undefined)).toBe(true); 13 | }); 14 | 15 | test('returns false for non-nil values', () => { 16 | expect(isNil(0)).toBe(false); 17 | expect(isNil('')).toBe(false); 18 | expect(isNil({})).toBe(false); 19 | expect(isNil(false)).toBe(false); 20 | }); 21 | }); 22 | 23 | describe('noop', () => { 24 | test('does not throw an error when called', () => { 25 | expect(() => noop()).not.toThrow(); 26 | }); 27 | 28 | test('is a function', () => { 29 | expect(typeof noop).toBe('function'); 30 | }); 31 | 32 | // 如果需要验证无副作用(可选) 33 | test('has no side effects', () => { 34 | const spy = vi.fn(); 35 | noop(spy); // 假设支持参数但不执行 36 | expect(spy).not.toHaveBeenCalled(); 37 | }); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /packages/vite-plugin-reverse-proxy/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Jesse Feng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/config/vite.reverse-proxy.1.mts: -------------------------------------------------------------------------------- 1 | import babel from '@vitejs/plugin-react'; 2 | import { defineConfig, Plugin } from 'vite'; 3 | import vitePluginExternal from 'vite-plugin-external'; 4 | import vitePluginReverseProxy from 'vite-plugin-reverse-proxy'; 5 | 6 | // https://vitejs.dev/config/ 7 | export default defineConfig({ 8 | plugins: [ 9 | babel({ 10 | jsxRuntime: 'classic' 11 | }) as unknown as Plugin, 12 | vitePluginExternal({ 13 | externals: { 14 | react: '$linkdesign.React', 15 | 'react-dom': '$linkdesign.ReactDOM', 16 | 'prop-types': '$linkdesign.PropTypes' 17 | } 18 | }), 19 | vitePluginReverseProxy({ 20 | preambleCode: babel.preambleCode, 21 | targets: { 22 | '/app.js': 'index.jsx' 23 | } 24 | }) 25 | ], 26 | server: { 27 | open: true 28 | }, 29 | build: { 30 | outDir: 'dist/reverse-proxy', 31 | cssCodeSplit: false, 32 | rollupOptions: { 33 | output: { 34 | manualChunks: undefined, 35 | assetFileNames: 'assets/[name][extname]', 36 | entryFileNames: '[name].js', 37 | format: 'iife' 38 | } 39 | } 40 | } 41 | }); 42 | -------------------------------------------------------------------------------- /packages/vite-plugin-separate-importer/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Jesse Feng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /docs/zh/plugins/vite-plugin-hook-use/quick-start.md: -------------------------------------------------------------------------------- 1 | # vite-plugin-hook-use 2 | 3 | [![npm package](https://nodei.co/npm/vite-plugin-hook-use.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/vite-plugin-hook-use) 4 | 5 | > 显示 `vite` 调用其钩子函数的序列和频率 6 | 7 | [![NPM version](https://img.shields.io/npm/v/vite-plugin-hook-use.svg?style=flat)](https://npmjs.org/package/vite-plugin-hook-use) 8 | [![NPM Downloads](https://img.shields.io/npm/dm/vite-plugin-hook-use.svg?style=flat)](https://npmjs.org/package/vite-plugin-hook-use) 9 | [![Node version](https://img.shields.io/node/v/vite-plugin-hook-use.svg?style=flat)](https://npmjs.org/package/vite-plugin-hook-use) 10 | 11 | ## Installation 12 | 13 | ::: code-group 14 | 15 | ```bash [npm] 16 | npm add vite-plugin-hook-use 17 | ``` 18 | ```bash [pnpm] 19 | pnpm add vite-plugin-hook-use 20 | ``` 21 | ```bash [yarn] 22 | yarn add vite-plugin-hook-use 23 | ``` 24 | 25 | ::: 26 | 27 | ## Usage 28 | 29 | ```js 30 | import { defineConfig } from 'vite'; 31 | import vitePluginHookUse from 'vite-plugin-hook-use'; 32 | 33 | export default defineConfig({ 34 | plugins: [ 35 | vitePluginHookUse() 36 | ] 37 | }); 38 | ``` 39 | -------------------------------------------------------------------------------- /examples/config/vite.external.7.mts: -------------------------------------------------------------------------------- 1 | import react from '@vitejs/plugin-react'; 2 | import type { Plugin } from 'vite'; 3 | import { defineConfig } from 'vite'; 4 | import vitePluginExternal from 'vite-plugin-external'; 5 | import { view } from 'vite-plugin-view'; 6 | 7 | // https://vitejs.dev/config/ 8 | export default defineConfig({ 9 | plugins: [ 10 | react({ 11 | jsxRuntime: 'classic' 12 | }) as unknown as Plugin, 13 | vitePluginExternal({ 14 | logLevel: 'TRACE', 15 | externals(libName) { 16 | if (libName === 'react') { 17 | return 'React'; 18 | } 19 | if (libName === 'react-dom/client') { 20 | return 'ReactDOM'; 21 | } 22 | } 23 | }) as unknown as Plugin, 24 | view({ 25 | engine: 'pug', 26 | engineOptions: { 27 | title: 'Vite + React + Pug', 28 | reactVersion: '18.x' 29 | } 30 | }) as unknown as Plugin 31 | ], 32 | server: { 33 | open: true 34 | }, 35 | build: { 36 | minify: false, 37 | outDir: 'dist/external/7', 38 | rollupOptions: { 39 | output: { 40 | format: 'iife' 41 | } 42 | } 43 | } 44 | }); 45 | -------------------------------------------------------------------------------- /packages/cs-runtime-helper/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cs-runtime-helper", 3 | "version": "1.0.0", 4 | "description": "Create starter runtime helper.", 5 | "types": "dist/index.d.ts", 6 | "module": "dist/index.mjs", 7 | "main": "dist/index.js", 8 | "engines": { 9 | "node": ">=14.18.0", 10 | "vite": ">=3.1.0" 11 | }, 12 | "scripts": { 13 | "build": "vite build", 14 | "watch": "vite build --watch", 15 | "prepublishOnly": "npm run build", 16 | "release": "npm publish" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "git+https://github.com/fengxinming/vite-plugins.git", 21 | "directory": "packages/cs-runtime-helper" 22 | }, 23 | "keywords": [ 24 | "vite", 25 | "cs-runtime-helper" 26 | ], 27 | "author": "Jesse Feng ", 28 | "license": "MIT", 29 | "bugs": { 30 | "url": "https://github.com/fengxinming/vite-plugins/issues" 31 | }, 32 | "homepage": "https://fengxinming.github.io/vite-plugins/", 33 | "devDependencies": { 34 | "@rollup/plugin-typescript": "^12.1.2", 35 | "vite": "^6.1.0" 36 | }, 37 | "dependencies": { 38 | "fs-extra": "^11.3.0" 39 | }, 40 | "files": [ 41 | "dist" 42 | ] 43 | } -------------------------------------------------------------------------------- /examples/config/vite.external.4.mts: -------------------------------------------------------------------------------- 1 | import react from '@vitejs/plugin-react'; 2 | import externalGlobals from 'rollup-plugin-external-globals'; 3 | import type { Plugin } from 'vite'; 4 | import { defineConfig } from 'vite'; 5 | import vitePluginExternal from 'vite-plugin-external'; 6 | import { view } from 'vite-plugin-view'; 7 | 8 | // https://vitejs.dev/config/ 9 | export default defineConfig({ 10 | plugins: [ 11 | react({ 12 | jsxRuntime: 'classic' 13 | }) as unknown as Plugin, 14 | vitePluginExternal({ 15 | externalGlobals, 16 | logLevel: 'TRACE', 17 | externals: { 18 | react: '$linkdesign.React', 19 | 'react-dom': '$linkdesign.ReactDOM', 20 | 'prop-types': '$linkdesign.PropTypes' 21 | } 22 | }) as unknown as Plugin, 23 | view({ 24 | engine: 'pug', 25 | engineOptions: { 26 | title: 'Vite + React + Pug', 27 | reactVersion: '16.x' 28 | } 29 | }) as unknown as Plugin 30 | ], 31 | server: { 32 | open: true 33 | }, 34 | build: { 35 | minify: false, 36 | outDir: 'dist/external/4', 37 | rollupOptions: { 38 | output: { 39 | format: 'iife' 40 | } 41 | } 42 | } 43 | }); 44 | -------------------------------------------------------------------------------- /docs/en/plugins/vite-plugin-hook-use/quick-start.md: -------------------------------------------------------------------------------- 1 | # vite-plugin-hook-use 2 | 3 | [![npm package](https://nodei.co/npm/vite-plugin-hook-use.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/vite-plugin-hook-use) 4 | 5 | > Displays the sequence and frequency of vite calling its hook functions. 6 | 7 | [![NPM version](https://img.shields.io/npm/v/vite-plugin-hook-use.svg?style=flat)](https://npmjs.org/package/vite-plugin-hook-use) 8 | [![NPM Downloads](https://img.shields.io/npm/dm/vite-plugin-hook-use.svg?style=flat)](https://npmjs.org/package/vite-plugin-hook-use) 9 | [![Node version](https://img.shields.io/node/v/vite-plugin-hook-use.svg?style=flat)](https://npmjs.org/package/vite-plugin-hook-use) 10 | 11 | ## Installation 12 | 13 | ::: code-group 14 | 15 | ```bash [npm] 16 | npm add vite-plugin-hook-use 17 | ``` 18 | ```bash [pnpm] 19 | pnpm add vite-plugin-hook-use 20 | ``` 21 | ```bash [yarn] 22 | yarn add vite-plugin-hook-use 23 | ``` 24 | 25 | ::: 26 | 27 | ## Usage 28 | 29 | ```js 30 | import { defineConfig } from 'vite'; 31 | import vitePluginHookUse from 'vite-plugin-hook-use'; 32 | 33 | export default defineConfig({ 34 | plugins: [ 35 | vitePluginHookUse() 36 | ] 37 | }); 38 | ``` 39 | -------------------------------------------------------------------------------- /examples/config/vite.external.3.mts: -------------------------------------------------------------------------------- 1 | import react from '@vitejs/plugin-react'; 2 | import type { Plugin } from 'vite'; 3 | import { defineConfig } from 'vite'; 4 | import vitePluginExternal from 'vite-plugin-external'; 5 | import { view } from 'vite-plugin-view'; 6 | 7 | // https://vitejs.dev/config/ 8 | export default defineConfig({ 9 | plugins: [ 10 | react({ 11 | jsxRuntime: 'classic' 12 | }) as unknown as Plugin, 13 | vitePluginExternal({ 14 | logLevel: 'TRACE', 15 | externals(libName) { 16 | if (libName === 'react') { 17 | return '$linkdesign.React'; 18 | } 19 | if (libName === 'react-dom') { 20 | return '$linkdesign.ReactDOM'; 21 | } 22 | if (libName === 'prop-types') { 23 | return '$linkdesign.PropTypes'; 24 | } 25 | } 26 | }) as unknown as Plugin, 27 | view({ 28 | engine: 'pug', 29 | engineOptions: { 30 | title: 'Vite + React + Pug', 31 | reactVersion: '16.x' 32 | } 33 | }) as unknown as Plugin 34 | ], 35 | server: { 36 | open: true 37 | }, 38 | build: { 39 | minify: false, 40 | outDir: 'dist/external/3', 41 | rollupOptions: { 42 | output: { 43 | format: 'iife' 44 | } 45 | } 46 | } 47 | }); 48 | -------------------------------------------------------------------------------- /examples/config/vite.view.3.mts: -------------------------------------------------------------------------------- 1 | import react from '@vitejs/plugin-react'; 2 | import nunjucks from 'nunjucks'; 3 | import { defineConfig, Plugin } from 'vite'; 4 | import vitePluginExternal from 'vite-plugin-external'; 5 | import { engineSource, view } from 'vite-plugin-view'; 6 | 7 | const env = new nunjucks.Environment(); 8 | 9 | env.addFilter('stringify', (obj) => { 10 | return JSON.stringify(obj, null, 2); 11 | }); 12 | 13 | engineSource.requires.nunjucks = env; 14 | 15 | // https://vitejs.dev/config/ 16 | export default defineConfig({ 17 | plugins: [ 18 | react({ 19 | jsxRuntime: 'classic' 20 | }) as unknown as Plugin, 21 | vitePluginExternal({ 22 | logLevel: 'TRACE', 23 | externals: { 24 | react: 'React', 25 | 'react-dom/client': 'ReactDOM' 26 | } 27 | }) as unknown as Plugin, 28 | view({ 29 | entry: 'index.njk', 30 | engine: 'nunjucks', 31 | extension: '.njk', 32 | logLevel: 'TRACE', 33 | engineOptions: { 34 | title: 'Vite + React' 35 | } 36 | }) as Plugin 37 | ], 38 | server: { 39 | open: true 40 | }, 41 | build: { 42 | minify: false, 43 | outDir: 'dist/view/3', 44 | rollupOptions: { 45 | output: { 46 | format: 'iife' 47 | } 48 | } 49 | } 50 | }); 51 | -------------------------------------------------------------------------------- /packages/cs-runtime-helper/src/generateStarter.ts: -------------------------------------------------------------------------------- 1 | import { readdirSync, readFileSync } from 'node:fs'; 2 | import { writeFile } from 'node:fs/promises'; 3 | import { EOL } from 'node:os'; 4 | import { join, resolve } from 'node:path'; 5 | 6 | import { copy } from 'fs-extra'; 7 | 8 | const filters = [ 9 | 'bin', 10 | 'dist', 11 | 'node_modules', 12 | 'package.json' 13 | ]; 14 | 15 | export async function generateStarter( 16 | templateDir: string, 17 | targetDir: string, 18 | pkg: Record 19 | ): Promise { 20 | templateDir = resolve(templateDir); 21 | targetDir = resolve(targetDir); 22 | 23 | const files = readdirSync(templateDir); 24 | await Promise.all(files.reduce((acc, file) => { 25 | if (!filters.includes(file)) { 26 | const targetPath = join(targetDir, file.startsWith('_') ? `.${file.slice(1)}` : file); 27 | acc.push(copy(join(templateDir, file), targetPath)); 28 | } 29 | return acc; 30 | }, [] as Array>)); 31 | 32 | const pkgJson = JSON.parse( 33 | readFileSync(join(templateDir, 'package.json'), 'utf-8'), 34 | ); 35 | delete pkgJson.bin; 36 | 37 | for (const [key, value] of Object.entries(pkg)) { 38 | pkgJson[key] = value; 39 | } 40 | 41 | await writeFile(join(targetDir, 'package.json'), `${JSON.stringify(pkgJson, null, 2)}${EOL}`, 'utf-8'); 42 | } 43 | -------------------------------------------------------------------------------- /docs/zh/guide/local-debugging.md: -------------------------------------------------------------------------------- 1 | # 本地调试 2 | 3 | ## 安装 4 | 5 | 使用 `npm run deps` 安装项目依赖: 6 | 7 | ```bash 8 | npm run deps 9 | ``` 10 | 11 | ## 脚本命令 12 | 13 | 项目中包含多个 npm 脚本命令,用于不同的开发和构建任务: 14 | 15 | - `deps`: 清理并安装依赖。 16 | - `clean`: 清理 `node_modules` 目录。 17 | - `eslint`: 运行 ESLint 进行代码格式化和 linting。 18 | - `build:packages`: 并行构建所有插件包。 19 | - `build:examples`: 并行构建所有示例项目。 20 | - `prepare`: 安装 Husky 钩子。 21 | - `docs:dev`: 启动项目文档开发服务器。 22 | - `docs:preview`: 预览项目文档。 23 | - `docs:build`: 生成项目文档。 24 | 25 | ## 目录结构 26 | 27 | ``` 28 | vite-plugins/ 29 | ├── examples/ # 示例项目 30 | ├── packages/ # 插件包 31 | │ ├── vite-plugin-combine/ 32 | │ ├── vite-plugin-cp/ 33 | │ ├── vite-plugin-external/ 34 | │ ├── vite-plugin-hook-use/ 35 | │ ├── vite-plugin-include-css/ 36 | │ ├── vite-plugin-mock-data/ 37 | │ ├── vite-plugin-reverse-proxy/ 38 | │ └── vite-plugin-separate-importer/ 39 | ├── package.json # 项目配置文件 40 | └── README.md # 英文 README 41 | ``` 42 | 43 | ## 示例项目 44 | 45 | 项目中包含多个示例项目,展示如何使用这些插件: 46 | 47 | * [vite3 demo](https://github.com/fengxinming/vite-plugins/tree/main/examples/vite3-demo) 48 | * [vite4 demo](https://github.com/fengxinming/vite-plugins/tree/main/examples/vite4-demo) 49 | * [vite5 demo](https://github.com/fengxinming/vite-plugins/tree/main/examples/vite5-demo) 50 | * [vite6 demo](https://github.com/fengxinming/vite-plugins/tree/main/examples/vite6-demo) -------------------------------------------------------------------------------- /examples/vite3-view/index.css: -------------------------------------------------------------------------------- 1 | :root { 2 | font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; 3 | line-height: 1.5; 4 | font-weight: 400; 5 | 6 | color-scheme: light dark; 7 | color: rgba(255, 255, 255, 0.87); 8 | background-color: #242424; 9 | 10 | font-synthesis: none; 11 | text-rendering: optimizeLegibility; 12 | -webkit-font-smoothing: antialiased; 13 | -moz-osx-font-smoothing: grayscale; 14 | } 15 | 16 | body { 17 | margin: 0; 18 | min-height: 100vh; 19 | } 20 | 21 | #root { 22 | width: 100%; 23 | text-align: center; 24 | } 25 | 26 | .box { 27 | max-width: 320px; 28 | margin: 0 auto; 29 | text-align: center; 30 | } 31 | 32 | h1 { 33 | font-size: 3.2em; 34 | line-height: 1.1; 35 | } 36 | 37 | button { 38 | border-radius: 8px; 39 | border: 1px solid transparent; 40 | padding: 0.6em 1.2em; 41 | font-size: 1em; 42 | font-weight: 500; 43 | font-family: inherit; 44 | background-color: #1a1a1a; 45 | cursor: pointer; 46 | transition: border-color 0.25s; 47 | } 48 | button:hover { 49 | border-color: #646cff; 50 | } 51 | button:focus, 52 | button:focus-visible { 53 | outline: 4px auto -webkit-focus-ring-color; 54 | } 55 | 56 | @media (prefers-color-scheme: light) { 57 | :root { 58 | color: #213547; 59 | background-color: #ffffff; 60 | } 61 | a:hover { 62 | color: #747bff; 63 | } 64 | button { 65 | background-color: #f9f9f9; 66 | } 67 | } -------------------------------------------------------------------------------- /examples/vite4-view/index.css: -------------------------------------------------------------------------------- 1 | :root { 2 | font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; 3 | line-height: 1.5; 4 | font-weight: 400; 5 | 6 | color-scheme: light dark; 7 | color: rgba(255, 255, 255, 0.87); 8 | background-color: #242424; 9 | 10 | font-synthesis: none; 11 | text-rendering: optimizeLegibility; 12 | -webkit-font-smoothing: antialiased; 13 | -moz-osx-font-smoothing: grayscale; 14 | } 15 | 16 | body { 17 | margin: 0; 18 | min-height: 100vh; 19 | } 20 | 21 | #root { 22 | width: 100%; 23 | text-align: center; 24 | } 25 | 26 | .box { 27 | max-width: 320px; 28 | margin: 0 auto; 29 | text-align: center; 30 | } 31 | 32 | h1 { 33 | font-size: 3.2em; 34 | line-height: 1.1; 35 | } 36 | 37 | button { 38 | border-radius: 8px; 39 | border: 1px solid transparent; 40 | padding: 0.6em 1.2em; 41 | font-size: 1em; 42 | font-weight: 500; 43 | font-family: inherit; 44 | background-color: #1a1a1a; 45 | cursor: pointer; 46 | transition: border-color 0.25s; 47 | } 48 | button:hover { 49 | border-color: #646cff; 50 | } 51 | button:focus, 52 | button:focus-visible { 53 | outline: 4px auto -webkit-focus-ring-color; 54 | } 55 | 56 | @media (prefers-color-scheme: light) { 57 | :root { 58 | color: #213547; 59 | background-color: #ffffff; 60 | } 61 | a:hover { 62 | color: #747bff; 63 | } 64 | button { 65 | background-color: #f9f9f9; 66 | } 67 | } -------------------------------------------------------------------------------- /examples/vite5-view/index.css: -------------------------------------------------------------------------------- 1 | :root { 2 | font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; 3 | line-height: 1.5; 4 | font-weight: 400; 5 | 6 | color-scheme: light dark; 7 | color: rgba(255, 255, 255, 0.87); 8 | background-color: #242424; 9 | 10 | font-synthesis: none; 11 | text-rendering: optimizeLegibility; 12 | -webkit-font-smoothing: antialiased; 13 | -moz-osx-font-smoothing: grayscale; 14 | } 15 | 16 | body { 17 | margin: 0; 18 | min-height: 100vh; 19 | } 20 | 21 | #root { 22 | width: 100%; 23 | text-align: center; 24 | } 25 | 26 | .box { 27 | max-width: 320px; 28 | margin: 0 auto; 29 | text-align: center; 30 | } 31 | 32 | h1 { 33 | font-size: 3.2em; 34 | line-height: 1.1; 35 | } 36 | 37 | button { 38 | border-radius: 8px; 39 | border: 1px solid transparent; 40 | padding: 0.6em 1.2em; 41 | font-size: 1em; 42 | font-weight: 500; 43 | font-family: inherit; 44 | background-color: #1a1a1a; 45 | cursor: pointer; 46 | transition: border-color 0.25s; 47 | } 48 | button:hover { 49 | border-color: #646cff; 50 | } 51 | button:focus, 52 | button:focus-visible { 53 | outline: 4px auto -webkit-focus-ring-color; 54 | } 55 | 56 | @media (prefers-color-scheme: light) { 57 | :root { 58 | color: #213547; 59 | background-color: #ffffff; 60 | } 61 | a:hover { 62 | color: #747bff; 63 | } 64 | button { 65 | background-color: #f9f9f9; 66 | } 67 | } -------------------------------------------------------------------------------- /examples/vite6-view/index.css: -------------------------------------------------------------------------------- 1 | :root { 2 | font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; 3 | line-height: 1.5; 4 | font-weight: 400; 5 | 6 | color-scheme: light dark; 7 | color: rgba(255, 255, 255, 0.87); 8 | background-color: #242424; 9 | 10 | font-synthesis: none; 11 | text-rendering: optimizeLegibility; 12 | -webkit-font-smoothing: antialiased; 13 | -moz-osx-font-smoothing: grayscale; 14 | } 15 | 16 | body { 17 | margin: 0; 18 | min-height: 100vh; 19 | } 20 | 21 | #root { 22 | width: 100%; 23 | text-align: center; 24 | } 25 | 26 | .box { 27 | max-width: 320px; 28 | margin: 0 auto; 29 | text-align: center; 30 | } 31 | 32 | h1 { 33 | font-size: 3.2em; 34 | line-height: 1.1; 35 | } 36 | 37 | button { 38 | border-radius: 8px; 39 | border: 1px solid transparent; 40 | padding: 0.6em 1.2em; 41 | font-size: 1em; 42 | font-weight: 500; 43 | font-family: inherit; 44 | background-color: #1a1a1a; 45 | cursor: pointer; 46 | transition: border-color 0.25s; 47 | } 48 | button:hover { 49 | border-color: #646cff; 50 | } 51 | button:focus, 52 | button:focus-visible { 53 | outline: 4px auto -webkit-focus-ring-color; 54 | } 55 | 56 | @media (prefers-color-scheme: light) { 57 | :root { 58 | color: #213547; 59 | background-color: #ffffff; 60 | } 61 | a:hover { 62 | color: #747bff; 63 | } 64 | button { 65 | background-color: #f9f9f9; 66 | } 67 | } -------------------------------------------------------------------------------- /docs/zh/plugins/vite-plugin-combine/usage.md: -------------------------------------------------------------------------------- 1 | # 使用示例 2 | 3 | 假设你有以下文件结构: 4 | 5 | ``` 6 | src/ 7 | |- components/ 8 | | |- Button.ts 9 | | |- Input.ts 10 | | |- Select.ts 11 | ``` 12 | 13 | 配置如下: 14 | 15 | ```typescript 16 | import { defineConfig } from 'vite'; 17 | import pluginCombine from 'vite-plugin-combine'; 18 | 19 | export default defineConfig({ 20 | plugins: [ 21 | pluginCombine({ 22 | src: 'src/components/**/*.ts', 23 | target: 'src/index.ts', 24 | exports: 'named', 25 | nameExport: (name, filePath) => `my${name}` 26 | }) 27 | ], 28 | build: { 29 | minify: false, 30 | lib: { 31 | entry: [], 32 | formats: ['es', 'cjs'], 33 | fileName: '[name]' 34 | } 35 | } 36 | }); 37 | ``` 38 | 39 | 输出的文件内容: 40 | 41 | `dist/index.mjs` 42 | ```js 43 | export { default as default2 } from './Button'; 44 | export { default as default3 } from './Input'; 45 | export { default as default4 } from './Select'; 46 | 47 | export { 48 | default2 as myButton, 49 | default3 as myInput, 50 | default4 as mySelect 51 | }; 52 | ``` 53 | 54 | `dist/index.js` 55 | ```js 56 | "use strict"; 57 | Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); 58 | const Button = require("./Button.js"); 59 | const Input = require("./Input.js"); 60 | const Select = require("./Select.js"); 61 | exports.Button = Button; 62 | exports.Input = Input; 63 | exports.Select = Select; 64 | ``` -------------------------------------------------------------------------------- /examples/vite3-demo/index.css: -------------------------------------------------------------------------------- 1 | :root { 2 | font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; 3 | line-height: 1.5; 4 | font-weight: 400; 5 | 6 | color-scheme: light dark; 7 | color: rgba(255, 255, 255, 0.87); 8 | background-color: #242424; 9 | 10 | font-synthesis: none; 11 | text-rendering: optimizeLegibility; 12 | -webkit-font-smoothing: antialiased; 13 | -moz-osx-font-smoothing: grayscale; 14 | } 15 | 16 | body { 17 | margin: 0; 18 | display: flex; 19 | place-items: center; 20 | min-height: 100vh; 21 | } 22 | 23 | #root { 24 | width: 100%; 25 | text-align: center; 26 | } 27 | 28 | .box { 29 | max-width: 320px; 30 | margin: 0 auto; 31 | text-align: center; 32 | } 33 | 34 | h1 { 35 | font-size: 3.2em; 36 | line-height: 1.1; 37 | } 38 | 39 | button { 40 | border-radius: 8px; 41 | border: 1px solid transparent; 42 | padding: 0.6em 1.2em; 43 | font-size: 1em; 44 | font-weight: 500; 45 | font-family: inherit; 46 | background-color: #1a1a1a; 47 | cursor: pointer; 48 | transition: border-color 0.25s; 49 | } 50 | button:hover { 51 | border-color: #646cff; 52 | } 53 | button:focus, 54 | button:focus-visible { 55 | outline: 4px auto -webkit-focus-ring-color; 56 | } 57 | 58 | @media (prefers-color-scheme: light) { 59 | :root { 60 | color: #213547; 61 | background-color: #ffffff; 62 | } 63 | a:hover { 64 | color: #747bff; 65 | } 66 | button { 67 | background-color: #f9f9f9; 68 | } 69 | } -------------------------------------------------------------------------------- /examples/vite4-demo/index.css: -------------------------------------------------------------------------------- 1 | :root { 2 | font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; 3 | line-height: 1.5; 4 | font-weight: 400; 5 | 6 | color-scheme: light dark; 7 | color: rgba(255, 255, 255, 0.87); 8 | background-color: #242424; 9 | 10 | font-synthesis: none; 11 | text-rendering: optimizeLegibility; 12 | -webkit-font-smoothing: antialiased; 13 | -moz-osx-font-smoothing: grayscale; 14 | } 15 | 16 | body { 17 | margin: 0; 18 | display: flex; 19 | place-items: center; 20 | min-height: 100vh; 21 | } 22 | 23 | #root { 24 | width: 100%; 25 | text-align: center; 26 | } 27 | 28 | .box { 29 | max-width: 320px; 30 | margin: 0 auto; 31 | text-align: center; 32 | } 33 | 34 | h1 { 35 | font-size: 3.2em; 36 | line-height: 1.1; 37 | } 38 | 39 | button { 40 | border-radius: 8px; 41 | border: 1px solid transparent; 42 | padding: 0.6em 1.2em; 43 | font-size: 1em; 44 | font-weight: 500; 45 | font-family: inherit; 46 | background-color: #1a1a1a; 47 | cursor: pointer; 48 | transition: border-color 0.25s; 49 | } 50 | button:hover { 51 | border-color: #646cff; 52 | } 53 | button:focus, 54 | button:focus-visible { 55 | outline: 4px auto -webkit-focus-ring-color; 56 | } 57 | 58 | @media (prefers-color-scheme: light) { 59 | :root { 60 | color: #213547; 61 | background-color: #ffffff; 62 | } 63 | a:hover { 64 | color: #747bff; 65 | } 66 | button { 67 | background-color: #f9f9f9; 68 | } 69 | } -------------------------------------------------------------------------------- /examples/vite5-demo/index.css: -------------------------------------------------------------------------------- 1 | :root { 2 | font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; 3 | line-height: 1.5; 4 | font-weight: 400; 5 | 6 | color-scheme: light dark; 7 | color: rgba(255, 255, 255, 0.87); 8 | background-color: #242424; 9 | 10 | font-synthesis: none; 11 | text-rendering: optimizeLegibility; 12 | -webkit-font-smoothing: antialiased; 13 | -moz-osx-font-smoothing: grayscale; 14 | } 15 | 16 | body { 17 | margin: 0; 18 | display: flex; 19 | place-items: center; 20 | min-height: 100vh; 21 | } 22 | 23 | #root { 24 | width: 100%; 25 | text-align: center; 26 | } 27 | 28 | .box { 29 | max-width: 320px; 30 | margin: 0 auto; 31 | text-align: center; 32 | } 33 | 34 | h1 { 35 | font-size: 3.2em; 36 | line-height: 1.1; 37 | } 38 | 39 | button { 40 | border-radius: 8px; 41 | border: 1px solid transparent; 42 | padding: 0.6em 1.2em; 43 | font-size: 1em; 44 | font-weight: 500; 45 | font-family: inherit; 46 | background-color: #1a1a1a; 47 | cursor: pointer; 48 | transition: border-color 0.25s; 49 | } 50 | button:hover { 51 | border-color: #646cff; 52 | } 53 | button:focus, 54 | button:focus-visible { 55 | outline: 4px auto -webkit-focus-ring-color; 56 | } 57 | 58 | @media (prefers-color-scheme: light) { 59 | :root { 60 | color: #213547; 61 | background-color: #ffffff; 62 | } 63 | a:hover { 64 | color: #747bff; 65 | } 66 | button { 67 | background-color: #f9f9f9; 68 | } 69 | } -------------------------------------------------------------------------------- /examples/vite6-demo/index.css: -------------------------------------------------------------------------------- 1 | :root { 2 | font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; 3 | line-height: 1.5; 4 | font-weight: 400; 5 | 6 | color-scheme: light dark; 7 | color: rgba(255, 255, 255, 0.87); 8 | background-color: #242424; 9 | 10 | font-synthesis: none; 11 | text-rendering: optimizeLegibility; 12 | -webkit-font-smoothing: antialiased; 13 | -moz-osx-font-smoothing: grayscale; 14 | } 15 | 16 | body { 17 | margin: 0; 18 | display: flex; 19 | place-items: center; 20 | min-height: 100vh; 21 | } 22 | 23 | #root { 24 | width: 100%; 25 | text-align: center; 26 | } 27 | 28 | .box { 29 | max-width: 320px; 30 | margin: 0 auto; 31 | text-align: center; 32 | } 33 | 34 | h1 { 35 | font-size: 3.2em; 36 | line-height: 1.1; 37 | } 38 | 39 | button { 40 | border-radius: 8px; 41 | border: 1px solid transparent; 42 | padding: 0.6em 1.2em; 43 | font-size: 1em; 44 | font-weight: 500; 45 | font-family: inherit; 46 | background-color: #1a1a1a; 47 | cursor: pointer; 48 | transition: border-color 0.25s; 49 | } 50 | button:hover { 51 | border-color: #646cff; 52 | } 53 | button:focus, 54 | button:focus-visible { 55 | outline: 4px auto -webkit-focus-ring-color; 56 | } 57 | 58 | @media (prefers-color-scheme: light) { 59 | :root { 60 | color: #213547; 61 | background-color: #ffffff; 62 | } 63 | a:hover { 64 | color: #747bff; 65 | } 66 | button { 67 | background-color: #f9f9f9; 68 | } 69 | } -------------------------------------------------------------------------------- /examples/config/vite.external.10.mts: -------------------------------------------------------------------------------- 1 | import react from '@vitejs/plugin-react'; 2 | import type { Plugin } from 'vite'; 3 | import { defineConfig } from 'vite'; 4 | import vitePluginExternal from 'vite-plugin-external'; 5 | import { view } from 'vite-plugin-view'; 6 | 7 | // https://vitejs.dev/config/ 8 | export default defineConfig({ 9 | plugins: [ 10 | react({ 11 | jsxRuntime: 'classic' 12 | }) as unknown as Plugin, 13 | vitePluginExternal({ 14 | logLevel: 'TRACE', 15 | externals: { 16 | react: 'https://esm.sh/react@18.3.1', 17 | 'react-dom/client': 'https://esm.sh/react-dom@18.3.1' 18 | } 19 | // externals(libName) { 20 | // if (libName === 'react') { 21 | // return 'https://esm.sh/react@18.3.1'; 22 | // } 23 | // if (libName === 'react-dom/client') { 24 | // return 'https://esm.sh/react-dom@18.3.1'; 25 | // } 26 | // } 27 | }) as unknown as Plugin, 28 | view({ 29 | engine: 'pug', 30 | engineOptions: { 31 | title: 'Vite + React + Pug', 32 | reactFormat: 'esm' 33 | } 34 | }) as unknown as Plugin 35 | ], 36 | // resolve: { 37 | // alias: { 38 | // react: 'https://esm.sh/react@18.3.1', 39 | // 'react-dom/client': 'https://esm.sh/react-dom@18.3.1' 40 | // } 41 | // }, 42 | server: { 43 | open: true 44 | }, 45 | build: { 46 | minify: false, 47 | outDir: 'dist/external/10' 48 | } 49 | }); 50 | -------------------------------------------------------------------------------- /packages/vite-plugin-mock-data/README.md: -------------------------------------------------------------------------------- 1 | # vite-plugin-mock-data 2 | 3 | [![npm package](https://nodei.co/npm/vite-plugin-mock-data.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/vite-plugin-mock-data) 4 | 5 | > Provides a simple way to mock data. 6 | 7 | [![NPM version](https://img.shields.io/npm/v/vite-plugin-mock-data.svg?style=flat)](https://npmjs.org/package/vite-plugin-mock-data) 8 | [![NPM Downloads](https://img.shields.io/npm/dm/vite-plugin-mock-data.svg?style=flat)](https://npmjs.org/package/vite-plugin-mock-data) 9 | [![Node version](https://img.shields.io/node/v/vite-plugin-mock-data.svg?style=flat)](https://npmjs.org/package/vite-plugin-mock-data) 10 | 11 | ## Installation 12 | 13 | ```bash 14 | npm install vite-plugin-mock-data --save-dev 15 | ``` 16 | 17 | ## Documentation 18 | 19 | For detailed usage instructions and API references, please visit the official documentation: 20 | 21 | 👉 [View Full Documentation](https://fengxinming.github.io/vite-plugins/plugins/vite-plugin-mock-data/quick-start) 22 | 23 | ## Contributing 24 | 25 | We welcome contributions from the community! If you find a bug or want to suggest an improvement, feel free to open an issue or submit a pull request. 26 | 27 | ### How to Contribute 28 | 1. Fork the repository. 29 | 2. Create a new branch for your changes. 30 | 3. Submit a pull request with a clear description of your changes. 31 | 32 | ## License 33 | 34 | This project is licensed under the [MIT License](LICENSE). -------------------------------------------------------------------------------- /packages/vite-plugin-reverse-proxy/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite-plugin-reverse-proxy", 3 | "version": "4.0.5", 4 | "description": "Makes the script to be served with the text/javascript MIME type instead of module MIME type.", 5 | "main": "./dist/index.js", 6 | "module": "./dist/index.mjs", 7 | "types": "./dist/index.d.ts", 8 | "exports": { 9 | ".": { 10 | "types": "./dist/index.d.ts", 11 | "import": "./dist/index.mjs", 12 | "require": "./dist/index.js" 13 | } 14 | }, 15 | "engines": { 16 | "node": ">=14.18.0", 17 | "vite": ">=3.1.0" 18 | }, 19 | "scripts": { 20 | "build": "vite build", 21 | "watch": "vite build --watch", 22 | "prepublishOnly": "npm run build", 23 | "release": "pnpm publish --no-git-checks" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "git+https://github.com/fengxinming/vite-plugins.git", 28 | "directory": "packages/vite-plugin-reverse-proxy" 29 | }, 30 | "keywords": [ 31 | "vite-plugin", 32 | "vite-plugin-reverse-proxy" 33 | ], 34 | "author": "Jesse Feng ", 35 | "license": "MIT", 36 | "bugs": { 37 | "url": "https://github.com/fengxinming/vite-plugins/issues" 38 | }, 39 | "homepage": "https://github.com/fengxinming/vite-plugins#readme", 40 | "devDependencies": { 41 | "@rollup/plugin-typescript": "^12.1.2", 42 | "@types/fs-extra": "^11.0.4", 43 | "vite": "^6.1.0" 44 | }, 45 | "files": [ 46 | "dist" 47 | ] 48 | } -------------------------------------------------------------------------------- /examples/config/vite.separate-importer.1.mts: -------------------------------------------------------------------------------- 1 | import react from '@vitejs/plugin-react'; 2 | import { decamelize } from 'camel-kit'; 3 | import { defineConfig, Plugin } from 'vite'; 4 | import pluginExternal from 'vite-plugin-external'; 5 | import pluginSeparateImporter from 'vite-plugin-separate-importer'; 6 | 7 | export default defineConfig({ 8 | plugins: [ 9 | react({ 10 | jsxRuntime: 'classic' 11 | }) as unknown as Plugin, 12 | pluginExternal({ 13 | externalizeDeps: ['antd', 'react'] 14 | }), 15 | pluginSeparateImporter({ 16 | logLevel: 'TRACE', 17 | libs: [ 18 | { 19 | name: 'antd', 20 | importFrom(importer, libName) { 21 | return { 22 | es: `${libName}/es/${decamelize(importer)}`, 23 | cjs: `${libName}/lib/${decamelize(importer)}` 24 | }; 25 | }, 26 | insertFrom(importer, libName) { 27 | return { 28 | es: `${libName}/es/${decamelize(importer)}/style`, 29 | cjs: `${libName}/lib/${decamelize(importer)}/style` 30 | }; 31 | } 32 | } 33 | ] 34 | }) 35 | ], 36 | build: { 37 | outDir: 'dist/separate-importer', 38 | minify: false, 39 | lib: { 40 | formats: ['es', 'cjs'], 41 | entry: ['src/separate-importer.jsx'], 42 | fileName(format, entryName) { 43 | return entryName + (format === 'es' ? '.mjs' : '.js'); 44 | } 45 | } 46 | } 47 | }); 48 | -------------------------------------------------------------------------------- /docs/en/plugins/vite-plugin-separate-importer/options.md: -------------------------------------------------------------------------------- 1 | # Option Reference 2 | 3 | ## `logLevel` 4 | * **Type:** `"TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR" | "FATAL" | "OFF"` 5 | * **Required:** `false` 6 | * **Default:** `"WARN"` 7 | 8 | ## `libs` 9 | * **Type:** `libConfig[]` 10 | * **Required:** `false` 11 | 12 | --- 13 | 14 | # TypeScript Type Definitions 15 | 16 | ```typescript 17 | import type { LogLevel } from 'vp-runtime-helper'; 18 | 19 | export interface ImportSource { 20 | es: string; 21 | cjs?: string; 22 | } 23 | 24 | export interface libConfig { 25 | /** 26 | * Name(s) of the library to be transformed, can be a single string or an array of strings. 27 | */ 28 | name: string | string[]; 29 | /** 30 | * New path for the module. 31 | */ 32 | importFrom?: (importer: string, libName: string) => string | ImportSource; 33 | /** 34 | * Specify the import source to insert. 35 | */ 36 | insertFrom?: (importer: string, libName: string) => string | ImportSource | Array; 37 | } 38 | 39 | export interface Options { 40 | /** 41 | * The value of `enforce` can be either `"pre"` or `"post"`, see more at https://vitejs.dev/guide/api-plugin.html#plugin-ordering. 42 | */ 43 | enforce?: 'pre' | 'post'; 44 | 45 | /** 46 | * Configuration interface defining libraries and their transformation logic. 47 | */ 48 | libs?: libConfig[]; 49 | 50 | /** 51 | * Log level for plugin output. 52 | */ 53 | logLevel?: LogLevel; 54 | } 55 | ``` -------------------------------------------------------------------------------- /docs/en/plugins/vite-plugin-combine/usage.md: -------------------------------------------------------------------------------- 1 | # Usage Examples 2 | 3 | Assuming the following file structure: 4 | 5 | ``` 6 | src/ 7 | |- components/ 8 | | |- Button.ts 9 | | |- Input.ts 10 | | |- Select.ts 11 | ``` 12 | 13 | Configure the plugin as: 14 | 15 | ```typescript 16 | import { defineConfig } from 'vite'; 17 | import pluginCombine from 'vite-plugin-combine'; 18 | 19 | export default defineConfig({ 20 | plugins: [ 21 | pluginCombine({ 22 | src: 'src/components/**/*.ts', 23 | target: 'src/index.ts', 24 | exports: 'named', 25 | nameExport: (name, filePath) => `my${name}` 26 | }) 27 | ], 28 | build: { 29 | minify: false, 30 | lib: { 31 | formats: ['es', 'cjs'], 32 | fileName: '[name]' 33 | } 34 | } 35 | }); 36 | ``` 37 | 38 | This will generate the following files: 39 | 40 | `dist/index.mjs` 41 | ```js 42 | export { default as default2 } from './Button'; 43 | export { default as default3 } from './Input'; 44 | export { default as default4 } from './Select'; 45 | 46 | export { 47 | default2 as myButton, 48 | default3 as myInput, 49 | default4 as mySelect 50 | }; 51 | ``` 52 | 53 | `dist/index.js` 54 | ```js 55 | "use strict"; 56 | Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); 57 | const Button = require("./Button.js"); 58 | const Input = require("./Input.js"); 59 | const Select = require("./Select.js"); 60 | exports.Button = Button; 61 | exports.Input = Input; 62 | exports.Select = Select; 63 | ``` -------------------------------------------------------------------------------- /packages/vite-plugin-separate-importer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite-plugin-separate-importer", 3 | "version": "6.1.1", 4 | "description": "Transform bulk imports from a single source module into individual file imports from the source module.", 5 | "types": "./dist/index.d.ts", 6 | "module": "./dist/index.mjs", 7 | "main": "./dist/index.js", 8 | "exports": { 9 | ".": { 10 | "types": "./dist/index.d.ts", 11 | "import": "./dist/index.mjs", 12 | "require": "./dist/index.js" 13 | } 14 | }, 15 | "engines": { 16 | "node": ">=14.18.0", 17 | "vite": ">=3.1.0" 18 | }, 19 | "scripts": { 20 | "build": "vite build", 21 | "watch": "vite build --watch", 22 | "prepublishOnly": "npm run build", 23 | "release": "pnpm publish --no-git-checks" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "git+https://github.com/fengxinming/vite-plugins.git", 28 | "directory": "packages/vite-plugin-separate-importer" 29 | }, 30 | "keywords": [ 31 | "vite-plugin", 32 | "vite-plugin-separate-importer" 33 | ], 34 | "author": "Jesse Feng ", 35 | "license": "MIT", 36 | "bugs": { 37 | "url": "https://github.com/fengxinming/vite-plugins/issues" 38 | }, 39 | "homepage": "https://fengxinming.github.io/vite-plugins/plugins/vite-plugin-separate-importer/quick-start", 40 | "dependencies": { 41 | "es-module-lexer": "^1.5.0", 42 | "vp-runtime-helper": "workspace:^" 43 | }, 44 | "files": [ 45 | "dist" 46 | ] 47 | } -------------------------------------------------------------------------------- /docs/zh/plugins/vite-plugin-include-css/quick-start.md: -------------------------------------------------------------------------------- 1 | # vite-plugin-include-css 2 | 3 | [![npm package](https://nodei.co/npm/vite-plugin-include-css.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/vite-plugin-include-css) 4 | 5 | > 当启用 `cssCodeSplit: false` 时,将所有CSS打包到单个JavaScript文件中。 6 | 7 | [![NPM version](https://img.shields.io/npm/v/vite-plugin-include-css.svg?style=flat)](https://npmjs.org/package/vite-plugin-include-css) 8 | [![NPM Downloads](https://img.shields.io/npm/dm/vite-plugin-include-css.svg?style=flat)](https://npmjs.org/package/vite-plugin-include-css) 9 | [![Node version](https://img.shields.io/node/v/vite-plugin-include-css.svg?style=flat)](https://npmjs.org/package/vite-plugin-include-css) 10 | 11 | ## Installation 12 | 13 | ::: code-group 14 | 15 | ```bash [npm] 16 | npm add vite-plugin-include-css 17 | ``` 18 | ```bash [pnpm] 19 | pnpm add vite-plugin-include-css 20 | ``` 21 | ```bash [yarn] 22 | yarn add vite-plugin-include-css 23 | ``` 24 | 25 | ::: 26 | 27 | ## Usage 28 | 29 | ```js 30 | import { defineConfig } from 'vite'; 31 | import includeCSS from 'vite-plugin-include-css'; 32 | 33 | export default defineConfig({ 34 | plugins: [ 35 | includeCSS() 36 | ], 37 | build: { 38 | cssCodeSplit: false, 39 | rollupOptions: { 40 | output: { 41 | manualChunks: undefined, 42 | assetFileNames: 'assets/[name][extname]', 43 | entryFileNames: '[name].js', 44 | format: 'iife' 45 | } 46 | } 47 | } 48 | }); 49 | ``` 50 | -------------------------------------------------------------------------------- /.github/workflows/npm-publish.yml: -------------------------------------------------------------------------------- 1 | # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created 2 | # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages 3 | 4 | name: npm publish 5 | 6 | on: 7 | pull_request: 8 | branches: [main] 9 | 10 | # 允许你从 Actions 选项卡手动运行此工作流程 11 | workflow_dispatch: 12 | 13 | jobs: 14 | build: 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: actions/checkout@v4 18 | - name: Setup Node.js 19 | uses: actions/setup-node@v4 20 | with: 21 | node-version: 20 22 | - name: Setup pnpm 23 | uses: pnpm/action-setup@v4 24 | with: 25 | version: 10 26 | - run: npm run deps 27 | - run: npm run test:all 28 | 29 | publish-npm: 30 | needs: build 31 | runs-on: ubuntu-latest 32 | steps: 33 | - uses: actions/checkout@v4 34 | - name: Setup Node.js 35 | uses: actions/setup-node@v4 36 | with: 37 | node-version: 20 38 | registry-url: https://registry.npmjs.org/ 39 | - name: Setup pnpm 40 | uses: pnpm/action-setup@v4 41 | with: 42 | version: 10 43 | - run: npm run deps 44 | - run: npm run build:vite-plugin-deps # 构建 vite-plugin 依赖 45 | - run: npm run build:starters # 构建 starter 依赖 46 | - run: npm run release:all # 发布所有包 47 | env: 48 | NODE_AUTH_TOKEN: ${{secrets.npm_token}} 49 | -------------------------------------------------------------------------------- /docs/en/plugins/vite-plugin-include-css/quick-start.md: -------------------------------------------------------------------------------- 1 | # vite-plugin-include-css 2 | 3 | [![npm package](https://nodei.co/npm/vite-plugin-include-css.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/vite-plugin-include-css) 4 | 5 | > When `cssCodeSplit: false` is enabled, all CSS will be bundled into a single JavaScript file. 6 | 7 | [![NPM version](https://img.shields.io/npm/v/vite-plugin-include-css.svg?style=flat)](https://npmjs.org/package/vite-plugin-include-css) 8 | [![NPM Downloads](https://img.shields.io/npm/dm/vite-plugin-include-css.svg?style=flat)](https://npmjs.org/package/vite-plugin-include-css) 9 | [![Node version](https://img.shields.io/node/v/vite-plugin-include-css.svg?style=flat)](https://npmjs.org/package/vite-plugin-include-css) 10 | 11 | ## Installation 12 | 13 | ::: code-group 14 | 15 | ```bash [npm] 16 | npm add vite-plugin-include-css 17 | ``` 18 | ```bash [pnpm] 19 | pnpm add vite-plugin-include-css 20 | ``` 21 | ```bash [yarn] 22 | yarn add vite-plugin-include-css 23 | ``` 24 | 25 | ::: 26 | 27 | ## Usage 28 | 29 | ```js 30 | import { defineConfig } from 'vite'; 31 | import includeCSS from 'vite-plugin-include-css'; 32 | 33 | export default defineConfig({ 34 | plugins: [ 35 | includeCSS() 36 | ], 37 | build: { 38 | cssCodeSplit: false, 39 | rollupOptions: { 40 | output: { 41 | manualChunks: undefined, 42 | assetFileNames: 'assets/[name][extname]', 43 | entryFileNames: '[name].js', 44 | format: 'iife' 45 | } 46 | } 47 | } 48 | }); 49 | ``` 50 | -------------------------------------------------------------------------------- /docs/zh/plugins/vite-plugin-combine/quick-start.md: -------------------------------------------------------------------------------- 1 | # vite-plugin-combine 2 | 3 | [![npm package](https://nodei.co/npm/vite-plugin-combine.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/vite-plugin-combine) 4 | 5 | > 将多个模块文件合并成一个目标文件。它支持命名导出、默认导出、自动导出和无导出四种模式,并可以根据配置自动生成相应的导入语句。 6 | 7 | [![NPM version](https://img.shields.io/npm/v/vite-plugin-combine.svg?style=flat)](https://npmjs.org/package/vite-plugin-combine) 8 | [![NPM Downloads](https://img.shields.io/npm/dm/vite-plugin-combine.svg?style=flat)](https://npmjs.org/package/vite-plugin-combine) 9 | [![Node version](https://img.shields.io/node/v/vite-plugin-combine.svg?style=flat)](https://npmjs.org/package/vite-plugin-combine) 10 | 11 | ## 安装 12 | 13 | ::: code-group 14 | 15 | ```bash [npm] 16 | npm add vite-plugin-combine 17 | ``` 18 | ```bash [pnpm] 19 | pnpm add vite-plugin-combine 20 | ``` 21 | ```bash [yarn] 22 | yarn add vite-plugin-combine 23 | ``` 24 | 25 | ::: 26 | 27 | ## 使用方法 28 | 29 | 在 `vite.config.ts` 中引入并配置插件: 30 | 31 | ```typescript 32 | import { defineConfig } from 'vite'; 33 | import pluginCombine from 'vite-plugin-combine'; 34 | 35 | export default defineConfig({ 36 | plugins: [ 37 | pluginCombine({ 38 | src: 'src/*.ts', // 匹配要组合的文件路径 39 | target: 'src/index.ts', // 目标文件路径 40 | exports: 'named', // 导出类型:'named' | 'default' | ‘both’ | 'none' 41 | }) 42 | ], 43 | build: { 44 | minify: false, 45 | lib: { 46 | entry: [], 47 | formats: ['es', 'cjs'], 48 | fileName: '[name]' 49 | } 50 | } 51 | }); 52 | ``` -------------------------------------------------------------------------------- /docs/en/plugins/vite-plugin-hook-use/usage.md: -------------------------------------------------------------------------------- 1 | Here is the translated English version of the document: 2 | 3 | --- 4 | 5 | # Usage Examples 6 | 7 | Assume you have the following file structure: 8 | 9 | ``` 10 | src/ 11 | |- index.js 12 | ``` 13 | 14 | Configure as follows: 15 | 16 | ```typescript 17 | import { defineConfig } from 'vite'; 18 | import vitePluginHookUse from 'vite-plugin-hook-use'; 19 | 20 | export default defineConfig({ 21 | plugins: [ 22 | vitePluginHookUse() 23 | ] 24 | }); 25 | ``` 26 | 27 | Run the following command: 28 | 29 | ```bash 30 | vite build 31 | ``` 32 | 33 | The console will output the following content, where numbers indicate the call count: 34 | 35 | ```bash 36 | ┌ === Start === 37 | │ 38 | ◇ config(1) 39 | │ 40 | ◇ configResolved(1) 41 | │ 42 | ◇ options(1) 43 | │ 44 | ◇ buildStart(1) 45 | │ 46 | ◇ load(1) 47 | │ 48 | ◇ transform(1) 49 | │ 50 | ◇ moduleParsed(1) 51 | │ 52 | ◇ buildEnd(1) 53 | │ 54 | ◇ outputOptions(1) 55 | │ 56 | ◇ renderStart(1) 57 | │ 58 | ◇ banner(1) 59 | │ 60 | ◇ footer(1) 61 | │ 62 | ◇ intro(1) 63 | │ 64 | ◇ outro(1) 65 | │ 66 | ◇ renderChunk(1) 67 | │ 68 | ◇ generateBundle(1) 69 | │ 70 | ◇ writeBundle(1) 71 | │ 72 | ◇ closeBundle(1) 73 | │ 74 | └ === End === 75 | ``` 76 | 77 | --- 78 | 79 | ### Explanation: 80 | - The plugin tracks and displays all Vite hook functions invoked during the build process. 81 | - Each line shows the **hook name** followed by its **call count** in parentheses. 82 | - The output helps visualize the execution sequence and frequency of Vite's internal hooks. -------------------------------------------------------------------------------- /packages/vp-runtime-helper/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vp-runtime-helper", 3 | "version": "1.0.10", 4 | "description": "Vite plugin runtime helper.", 5 | "types": "./dist/index.d.ts", 6 | "module": "./dist/index.mjs", 7 | "main": "./dist/index.js", 8 | "exports": { 9 | ".": { 10 | "types": "./dist/index.d.ts", 11 | "import": "./dist/index.mjs", 12 | "require": "./dist/index.js" 13 | } 14 | }, 15 | "engines": { 16 | "node": ">=14.18.0", 17 | "vite": ">=3.1.0" 18 | }, 19 | "scripts": { 20 | "build": "vite build", 21 | "watch": "vite build --watch", 22 | "prepublishOnly": "npm run build", 23 | "release": "npm publish" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "git+https://github.com/fengxinming/vite-plugins.git", 28 | "directory": "packages/vp-runtime-helper" 29 | }, 30 | "keywords": [ 31 | "vite-plugin", 32 | "vp-runtime-helper" 33 | ], 34 | "author": "Jesse Feng ", 35 | "license": "MIT", 36 | "bugs": { 37 | "url": "https://github.com/fengxinming/vite-plugins/issues" 38 | }, 39 | "homepage": "https://fengxinming.github.io/vite-plugins/", 40 | "dependencies": { 41 | "@types/fs-extra": "^11.0.4", 42 | "base-log-factory": "^2.1.4", 43 | "blf-debug-appender": "^1.0.2", 44 | "figlet": "^1.8.0", 45 | "fs-extra": "^11.3.0", 46 | "picocolors": "^1.0.0" 47 | }, 48 | "devDependencies": { 49 | "@rollup/plugin-typescript": "^12.1.2", 50 | "vite": "^6.1.0" 51 | }, 52 | "files": [ 53 | "dist" 54 | ] 55 | } -------------------------------------------------------------------------------- /packages/create-vite-lib-starter/README.md: -------------------------------------------------------------------------------- 1 | # create-vite-lib-starter 2 | 3 | [![NPM version](https://img.shields.io/npm/v/create-vite-lib-starter.svg?style=flat)](https://npmjs.org/package/create-vite-lib-starter) 4 | [![NPM Downloads](https://img.shields.io/npm/dm/create-vite-lib-starter.svg?style=flat)](https://npmjs.org/package/create-vite-lib-starter) 5 | [![Node version](https://img.shields.io/node/v/create-vite-lib-starter.svg?style=flat)](https://npmjs.org/package/create-vite-lib-starter) 6 | 7 | > Quickly generate a Vite library project template with basic configuration and development environment. 8 | 9 | ## Usage 10 | 11 | Run in the terminal: 12 | 13 | ```bash 14 | npm create vite-lib-starter@latest 15 | ``` 16 | 17 | Example: 18 | 19 | ```bash 20 | npm create vite-lib-starter@latest my-vite-lib 21 | ``` 22 | 23 | This will create a new directory named `my-vite-lib` in the current folder with the initialized project structure. 24 | 25 | --- 26 | 27 | ## Quick Start 28 | 29 | 1. **Navigate to the project directory:** 30 | ```bash 31 | cd my-vite-lib 32 | ``` 33 | 34 | 2. **Start the development server:** 35 | ```bash 36 | npm run dev 37 | # or 38 | yarn dev 39 | ``` 40 | 41 | 3. **Build for production:** 42 | ```bash 43 | npm run build 44 | # or 45 | yarn build 46 | ``` 47 | 48 | 4. **Run tests:** 49 | ```bash 50 | npm test 51 | # or 52 | yarn test 53 | ``` 54 | 55 | --- 56 | 57 | ## Notes 58 | - The project name must comply with **npm package name conventions** (lowercase letters, numbers, hyphens). 59 | -------------------------------------------------------------------------------- /packages/vite-plugin-include-css/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite-plugin-include-css", 3 | "version": "6.0.0", 4 | "description": "Bundles all CSS into a single JavaScript file when `cssCodeSplit: false` is enabled.", 5 | "main": "./dist/index.js", 6 | "module": "./dist/index.mjs", 7 | "types": "./dist/index.d.ts", 8 | "exports": { 9 | ".": { 10 | "types": "./dist/index.d.ts", 11 | "import": "./dist/index.mjs", 12 | "require": "./dist/index.js" 13 | } 14 | }, 15 | "scripts": { 16 | "build": "vite build", 17 | "watch": "vite build --watch", 18 | "prepublishOnly": "npm run build", 19 | "release": "pnpm publish --no-git-checks" 20 | }, 21 | "engines": { 22 | "node": ">=14.18.0", 23 | "vite": ">=3.1.0" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "git+https://github.com/fengxinming/vite-plugins.git", 28 | "directory": "packages/vite-plugin-include-css" 29 | }, 30 | "keywords": [ 31 | "vite-plugin", 32 | "vite-plugin-include-css" 33 | ], 34 | "author": "Jesse Feng ", 35 | "license": "MIT", 36 | "bugs": { 37 | "url": "https://github.com/fengxinming/vite-plugins/issues" 38 | }, 39 | "homepage": "https://fengxinming.github.io/vite-plugins/plugins/vite-plugin-include-css/quick-start", 40 | "devDependencies": { 41 | "@rollup/plugin-typescript": "^12.1.2", 42 | "vite": "^6.1.0" 43 | }, 44 | "files": [ 45 | "dist" 46 | ], 47 | "dependencies": { 48 | "magic-string": "^0.30.17", 49 | "terser": "^5.39.0", 50 | "vp-runtime-helper": "workspace:^" 51 | } 52 | } -------------------------------------------------------------------------------- /packages/vite-plugin-hook-use/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite-plugin-hook-use", 3 | "version": "6.0.2", 4 | "description": "Displays the sequence and frequency of vite calling its hook functions.", 5 | "types": "./dist/index.d.ts", 6 | "module": "./dist/index.mjs", 7 | "main": "./dist/index.js", 8 | "exports": { 9 | ".": { 10 | "types": "./dist/index.d.ts", 11 | "import": "./dist/index.mjs", 12 | "require": "./dist/index.js" 13 | } 14 | }, 15 | "engines": { 16 | "node": ">=14.18.0", 17 | "vite": ">=3.1.0" 18 | }, 19 | "scripts": { 20 | "build": "vite build", 21 | "watch": "vite build --watch", 22 | "prepublishOnly": "npm run build", 23 | "release": "pnpm publish --no-git-checks" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "git+https://github.com/fengxinming/vite-plugins.git", 28 | "directory": "packages/vite-plugin-hook-use" 29 | }, 30 | "keywords": [ 31 | "vite-plugin", 32 | "vite-plugin-hook-use" 33 | ], 34 | "author": "Jesse Feng ", 35 | "license": "MIT", 36 | "bugs": { 37 | "url": "https://github.com/fengxinming/vite-plugins/issues" 38 | }, 39 | "homepage": "https://fengxinming.github.io/vite-plugins/plugins/vite-plugin-hook-use/quick-start", 40 | "dependencies": { 41 | "@clack/prompts": "^0.7.0", 42 | "fs-extra": "^11.1.1", 43 | "picocolors": "^1.0.0", 44 | "vp-runtime-helper": "workspace:^" 45 | }, 46 | "devDependencies": { 47 | "@rollup/plugin-typescript": "^12.1.2", 48 | "vite": "^6.1.0" 49 | }, 50 | "files": [ 51 | "dist" 52 | ] 53 | } -------------------------------------------------------------------------------- /packages/vite-plugin-build-chunk/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite-plugin-build-chunk", 3 | "version": "6.0.0", 4 | "description": "Generate additional build artifacts (e.g., chunk files in different formats) after Vite's main build process. Ideal for scenarios requiring multi-format outputs or secondary builds.", 5 | "types": "./dist/index.d.ts", 6 | "module": "./dist/index.mjs", 7 | "main": "./dist/index.js", 8 | "exports": { 9 | ".": { 10 | "types": "./dist/index.d.ts", 11 | "import": "./dist/index.mjs", 12 | "require": "./dist/index.js" 13 | } 14 | }, 15 | "engines": { 16 | "node": ">=14.18.0", 17 | "vite": ">=3.1.0" 18 | }, 19 | "scripts": { 20 | "build": "vite build", 21 | "watch": "vite build --watch", 22 | "prepublishOnly": "npm run build", 23 | "release": "pnpm publish --no-git-checks" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "git+https://github.com/fengxinming/vite-plugins.git", 28 | "directory": "packages/vite-plugin-build-chunk" 29 | }, 30 | "keywords": [ 31 | "vite-plugin", 32 | "vite-plugin-build-chunk" 33 | ], 34 | "author": "Jesse Feng ", 35 | "license": "MIT", 36 | "bugs": { 37 | "url": "https://github.com/fengxinming/vite-plugins/issues" 38 | }, 39 | "homepage": "https://fengxinming.github.io/vite-plugins/plugins/vite-plugin-build-chunk/quick-start", 40 | "dependencies": { 41 | "vp-runtime-helper": "workspace:^" 42 | }, 43 | "devDependencies": { 44 | "@rollup/plugin-typescript": "^12.1.2", 45 | "vite": "^6.1.0" 46 | }, 47 | "files": [ 48 | "dist" 49 | ] 50 | } -------------------------------------------------------------------------------- /packages/vite-plugin-external/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite-plugin-external", 3 | "version": "6.2.2", 4 | "description": "Excludes specified module dependencies from runtime code and built bundles.", 5 | "types": "./dist/index.d.ts", 6 | "module": "./dist/index.mjs", 7 | "main": "./dist/index.js", 8 | "exports": { 9 | ".": { 10 | "types": "./dist/index.d.ts", 11 | "import": "./dist/index.mjs", 12 | "require": "./dist/index.js" 13 | } 14 | }, 15 | "scripts": { 16 | "build": "vite build", 17 | "watch": "vite build --watch", 18 | "prepublishOnly": "npm run build", 19 | "release": "pnpm publish --no-git-checks" 20 | }, 21 | "engines": { 22 | "node": ">=14.18.0", 23 | "vite": ">=3.1.0" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "git+https://github.com/fengxinming/vite-plugins.git", 28 | "directory": "packages/vite-plugin-external" 29 | }, 30 | "keywords": [ 31 | "vite", 32 | "vite-plugin", 33 | "vite-plugin-external" 34 | ], 35 | "author": "Jesse Feng ", 36 | "license": "MIT", 37 | "bugs": { 38 | "url": "https://github.com/fengxinming/vite-plugins/issues" 39 | }, 40 | "homepage": "https://fengxinming.github.io/vite-plugins/plugins/vite-plugin-external/quick-start", 41 | "dependencies": { 42 | "@types/fs-extra": "^11.0.4", 43 | "fs-extra": "^11.1.1", 44 | "is-what-type": "^1.1.4", 45 | "vp-runtime-helper": "workspace:^" 46 | }, 47 | "devDependencies": { 48 | "@rollup/plugin-typescript": "^12.1.2", 49 | "vite": "^6.1.0" 50 | }, 51 | "files": [ 52 | "dist" 53 | ] 54 | } -------------------------------------------------------------------------------- /packages/vite-plugin-mock-data/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite-plugin-mock-data", 3 | "version": "6.0.3", 4 | "description": "Provides a simple way to mock data.", 5 | "main": "./dist/index.js", 6 | "module": "./dist/index.mjs", 7 | "types": "./dist/index.d.ts", 8 | "exports": { 9 | ".": { 10 | "types": "./dist/index.d.ts", 11 | "import": "./dist/index.mjs", 12 | "require": "./dist/index.js" 13 | } 14 | }, 15 | "engines": { 16 | "node": ">=14.18.0", 17 | "vite": ">=3.1.0" 18 | }, 19 | "scripts": { 20 | "build": "vite build", 21 | "watch": "vite build --watch", 22 | "prepublishOnly": "npm run build", 23 | "release": "pnpm publish --no-git-checks" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "git+https://github.com/fengxinming/vite-plugins.git", 28 | "directory": "packages/vite-plugin-mock-data" 29 | }, 30 | "keywords": [ 31 | "vite-plugin", 32 | "vite-plugin-mock-data" 33 | ], 34 | "author": "Jesse Feng ", 35 | "license": "MIT", 36 | "bugs": { 37 | "url": "https://github.com/fengxinming/vite-plugins/issues" 38 | }, 39 | "homepage": "https://fengxinming.github.io/vite-plugins/plugins/vite-plugin-mock-data/quick-start", 40 | "dependencies": { 41 | "find-my-way": "^9.2.0", 42 | "is-what-type": "^1.1.4", 43 | "sirv": "^3.0.1", 44 | "tinyglobby": "^0.2.12", 45 | "vp-runtime-helper": "workspace:^" 46 | }, 47 | "devDependencies": { 48 | "@rollup/plugin-typescript": "^12.1.2", 49 | "@types/fs-extra": "^11.0.4", 50 | "vite": "^6.1.0" 51 | }, 52 | "files": [ 53 | "dist" 54 | ] 55 | } -------------------------------------------------------------------------------- /docs/zh/plugins/vite-plugin-separate-importer/options.md: -------------------------------------------------------------------------------- 1 | # 配置选项参考 2 | 3 | ## `logLevel` 4 | * **类型:** `"TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR" | "FATAL" | "OFF"` 5 | * **必填:** `false` 6 | * **默认值:** `"WARN"` 7 | 8 | ## `libs` 9 | * **类型:** `libConfig[]` 10 | * **必填:** `false` 11 | 12 | --- 13 | 14 | ## TypeScript 类型定义 15 | 16 | ```typescript 17 | import type { LogLevel } from 'vp-runtime-helper'; 18 | export interface ImportSource { 19 | es: string; 20 | cjs?: string; 21 | } 22 | 23 | export interface libConfig { 24 | /** 25 | * 待转换的库名称,可以是单个字符串或字符串数组 26 | * Library name(s) to be transformed, can be a single string or an array of strings 27 | */ 28 | name: string | string[]; 29 | /** 30 | * 模块的新路径 31 | * New path for the module 32 | */ 33 | importFrom?: (importer: string, libName: string) => string | ImportSource; 34 | /** 35 | * 插入导入声明 36 | * Insert import source 37 | */ 38 | insertFrom?: (importer: string, libName: string) => string | ImportSource | Array; 39 | } 40 | 41 | export interface Options { 42 | /** 43 | * The value of enforce can be either `"pre"` or `"post"`, see more at https://vitejs.dev/guide/api-plugin.html#plugin-ordering. 44 | * 45 | * 强制执行顺序,`pre` 前,`post` 后,参考 https://cn.vitejs.dev/guide/api-plugin.html#plugin-ordering。 46 | */ 47 | enforce?: 'pre' | 'post'; 48 | 49 | /** 50 | * 插件配置接口,用于定义待转换的库名称及其处理逻辑 51 | * Interface for plugin configuration to define the library names and processing logic 52 | */ 53 | libs?: libConfig[]; 54 | 55 | 56 | /** 57 | * 输出日志等级 58 | * Output log level 59 | */ 60 | logLevel?: LogLevel; 61 | } 62 | ``` -------------------------------------------------------------------------------- /packages/vite-plugin-separate-importer/README.md: -------------------------------------------------------------------------------- 1 | # vite-plugin-separate-importer 2 | 3 | [![npm package](https://nodei.co/npm/vite-plugin-separate-importer.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/vite-plugin-separate-importer) 4 | 5 | > Transform bulk imports from a single source module into individual file imports from the source module (Vite >= 3.1) 6 | 7 | [![NPM version](https://img.shields.io/npm/v/vite-plugin-separate-importer.svg?style=flat)](https://npmjs.org/package/vite-plugin-separate-importer) 8 | [![NPM Downloads](https://img.shields.io/npm/dm/vite-plugin-separate-importer.svg?style=flat)](https://npmjs.org/package/vite-plugin-separate-importer) 9 | [![Node version](https://img.shields.io/node/v/vite-plugin-separate-importer.svg?style=flat)](https://npmjs.org/package/vite-plugin-separate-importer) 10 | 11 | ## Installation 12 | 13 | ```bash 14 | npm install vite-plugin-separate-importer --save-dev 15 | ``` 16 | 17 | ## Documentation 18 | 19 | For detailed usage instructions and API references, please visit the official documentation: 20 | 21 | 👉 [View Full Documentation](https://fengxinming.github.io/vite-plugins/plugins/vite-plugin-separate-importer/quick-start) 22 | 23 | ## Contributing 24 | 25 | We welcome contributions from the community! If you find a bug or want to suggest an improvement, feel free to open an issue or submit a pull request. 26 | 27 | ### How to Contribute 28 | 1. Fork the repository. 29 | 2. Create a new branch for your changes. 30 | 3. Submit a pull request with a clear description of your changes. 31 | 32 | ## License 33 | 34 | This project is licensed under the [MIT License](LICENSE). -------------------------------------------------------------------------------- /docs/en/guide/introduction.md: -------------------------------------------------------------------------------- 1 | # vite-plugins 2 | 3 | > `vite-plugins` is a collection of custom plugins designed to enhance the functionality of the Vite build tool. 4 | 5 | ## Plugin List 6 | 7 | * [vite-plugin-combine](/plugins/vite-plugin-combine/quick-start) - Combines multiple module files into a single target file. It supports four modes: named exports, default exports, auto exports, and no exports, and automatically generates corresponding import statements based on configuration. 8 | 9 | * [vite-plugin-cp](/plugins/vite-plugin-cp/quick-start) - A Vite plugin for copying files/directories, supporting flexible content transformations, directory structure preservation or flattening, and custom file renaming. 10 | 11 | * [vite-plugin-external](/plugins/vite-plugin-external/quick-start) - Excludes specified module dependencies from runtime code and bundled outputs. 12 | 13 | * [vite-plugin-hook-use](/plugins/vite-plugin-hook-use/quick-start) - Displays the sequence and frequency of Vite's hook function invocations. 14 | 15 | * [vite-plugin-include-css](/plugins/vite-plugin-include-css/quick-start) - Bundles all CSS into a single JavaScript file when `cssCodeSplit: false` is enabled. 16 | 17 | * [vite-plugin-mock-data](/plugins/vite-plugin-mock-data/quick-start) - Provides a simple way to mock data. 18 | 19 | * [vite-plugin-separate-importer](/plugins/vite-plugin-separate-importer/quick-start) - Converts batch imports from a source module into individual file imports from subdirectories of the source module. 20 | 21 | * [vite-plugin-view](/plugins/vite-plugin-view/quick-start) - Dynamically render pages using custom template engines instead of the static `.html` entry file. -------------------------------------------------------------------------------- /packages/vite-plugin-cp/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite-plugin-cp", 3 | "version": "6.0.3", 4 | "description": "A powerful Vite plugin for copying files/directories with advanced transformation and renaming capabilities.", 5 | "types": "./dist/index.d.ts", 6 | "module": "./dist/index.mjs", 7 | "main": "./dist/index.js", 8 | "exports": { 9 | ".": { 10 | "types": "./dist/index.d.ts", 11 | "import": "./dist/index.mjs", 12 | "require": "./dist/index.js" 13 | } 14 | }, 15 | "engines": { 16 | "node": ">=14.18.0", 17 | "vite": ">=3.1.0" 18 | }, 19 | "scripts": { 20 | "build": "vite build", 21 | "watch": "vite build --watch", 22 | "prepublishOnly": "npm run build", 23 | "release": "pnpm publish --no-git-checks" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "git+https://github.com/fengxinming/vite-plugins.git", 28 | "directory": "packages/vite-plugin-cp" 29 | }, 30 | "keywords": [ 31 | "vite", 32 | "vite-plugin", 33 | "vite-plugin-cp" 34 | ], 35 | "author": "Jesse Feng ", 36 | "license": "MIT", 37 | "bugs": { 38 | "url": "https://github.com/fengxinming/vite-plugins/issues" 39 | }, 40 | "homepage": "https://fengxinming.github.io/vite-plugins/plugins/vite-plugin-cp/quick-start", 41 | "dependencies": { 42 | "fs-extra": "^11.3.0", 43 | "is-what-type": "^1.1.4", 44 | "tinyglobby": "^0.2.12", 45 | "vp-runtime-helper": "workspace:^" 46 | }, 47 | "devDependencies": { 48 | "@rollup/plugin-typescript": "^12.1.2", 49 | "@types/fs-extra": "^11.0.4", 50 | "vite": "^6.1.0" 51 | }, 52 | "files": [ 53 | "dist" 54 | ] 55 | } -------------------------------------------------------------------------------- /packages/vite-plugin-view/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite-plugin-view", 3 | "version": "6.0.1", 4 | "description": "Dynamically render pages using custom template engines instead of the static `index.html` entry file.", 5 | "types": "./dist/index.d.ts", 6 | "module": "./dist/index.mjs", 7 | "main": "./dist/index.js", 8 | "exports": { 9 | ".": { 10 | "types": "./dist/index.d.ts", 11 | "import": "./dist/index.mjs", 12 | "require": "./dist/index.js" 13 | } 14 | }, 15 | "engines": { 16 | "node": ">=14.18.0", 17 | "vite": ">=3.1.0" 18 | }, 19 | "scripts": { 20 | "build": "vite build", 21 | "watch": "vite build --watch", 22 | "prepublishOnly": "npm run build", 23 | "release": "pnpm publish --no-git-checks" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "git+https://github.com/fengxinming/vite-plugins.git", 28 | "directory": "packages/vite-plugin-view" 29 | }, 30 | "keywords": [ 31 | "vite-plugin", 32 | "vite-plugin-view", 33 | "engine", 34 | "template", 35 | "view" 36 | ], 37 | "author": "Jesse Feng ", 38 | "license": "MIT", 39 | "bugs": { 40 | "url": "https://github.com/fengxinming/vite-plugins/issues" 41 | }, 42 | "homepage": "https://fengxinming.github.io/vite-plugins/plugins/vite-plugin-view/quick-start", 43 | "dependencies": { 44 | "@types/consolidate": "^0.14.4", 45 | "consolidate": "^1.0.4", 46 | "pretty": "^2.0.0", 47 | "vp-runtime-helper": "workspace:^" 48 | }, 49 | "devDependencies": { 50 | "@rollup/plugin-typescript": "^12.1.2", 51 | "vite": "^6.1.0" 52 | }, 53 | "files": [ 54 | "dist" 55 | ] 56 | } -------------------------------------------------------------------------------- /packages/vite-plugin-mock-data/src/types.ts: -------------------------------------------------------------------------------- 1 | import { Config as SirvConfig, Handler, HTTPVersion, RouteOptions } from 'find-my-way'; 2 | import { LogLevel } from 'vp-runtime-helper'; 3 | 4 | export interface HandleRoute { 5 | file?: string; 6 | handler?: any | Handler; 7 | options?: RouteOptions; 8 | store?: any; 9 | } 10 | 11 | export interface RouteConfig { 12 | [route: string]: string | Handler | HandleRoute; 13 | } 14 | 15 | export interface Options { 16 | /** 17 | * The directory to serve files from. 18 | * @default `process.cwd()` 19 | */ 20 | cwd?: string; 21 | 22 | /** 23 | * Cache directory for compiled files. 24 | * 25 | * 用于存放 ts 被编译后存放的文件目录。 26 | * 27 | * @default `${cwd}/node_modules/.vite_mock_data` 28 | */ 29 | cacheDir?: string; 30 | 31 | /** 32 | * Log level 33 | * 34 | * 输出日志等级 35 | */ 36 | logLevel?: LogLevel; 37 | 38 | /** 39 | * If `true`, these mock routes is matched after internal middlewares are installed. 40 | * @default `false` 41 | */ 42 | isAfter?: boolean; 43 | 44 | /** 45 | * Initial options of `find-my-way`. see more at https://github.com/delvedor/find-my-way#findmywayoptions 46 | */ 47 | routerOptions?: SirvConfig | SirvConfig; 48 | 49 | /** 50 | * Initial list of mock routes that should be added to the dev server 51 | * or specify the directory to define mock routes that should be added to the dev server. 52 | */ 53 | routes?: RouteConfig | Array | string; 54 | 55 | /** 56 | * Whether to output the banner 57 | * 58 | * 是否输出 banner 59 | */ 60 | enableBanner?: boolean; 61 | } 62 | -------------------------------------------------------------------------------- /packages/vite-plugin-build-chunk/src/types.ts: -------------------------------------------------------------------------------- 1 | import { ModuleFormat } from 'rollup'; 2 | import type { LibraryFormats, PluginOption } from 'vite'; 3 | import { LogLevel } from 'vp-runtime-helper'; 4 | 5 | export interface BuildOptions { 6 | /** 7 | * The chunk name. 8 | * 9 | * 构建的 chunk 名称。 10 | */ 11 | chunk: string; 12 | /** 13 | * Global variable name. 14 | * 15 | * 全局变量名。 16 | */ 17 | name: string; 18 | /** 19 | * The output format. 20 | * 21 | * 输出格式。 22 | */ 23 | format?: LibraryFormats; 24 | /** 25 | * Whether to generate sourcemaps. 26 | * 27 | * 是否生成 sourcemap。 28 | */ 29 | sourcemap?: boolean | 'inline' | 'hidden'; 30 | /** 31 | * The exports type. 32 | * 33 | * 导出类型。 34 | */ 35 | exports?: 'default' | 'named' | 'none' | 'auto'; 36 | /** 37 | * Whether to minify the output. 38 | * 39 | * 是否压缩输出。 40 | */ 41 | minify?: boolean | 'terser' | 'esbuild'; 42 | /** 43 | * The output directory. 44 | * 45 | * 输出目录。 46 | */ 47 | outDir?: string; 48 | /** 49 | * The output file name. 50 | * 51 | * 输出文件名。 52 | */ 53 | fileName?: string | ((format: ModuleFormat, entryName: string) => string); 54 | /** 55 | * The plugins to use. 56 | * 57 | * 使用的插件。 58 | */ 59 | plugins?: PluginOption[]; 60 | } 61 | 62 | export interface Options { 63 | /** 64 | * The build options. 65 | * 66 | * 构建选项。 67 | */ 68 | build: BuildOptions | BuildOptions[]; 69 | 70 | /** 71 | * The log level to use. 72 | * 73 | * 日志等级。 74 | */ 75 | logLevel?: LogLevel; 76 | 77 | /** 78 | * Whether to output the banner 79 | * 80 | * 是否输出 banner 81 | */ 82 | enableBanner?: boolean; 83 | } 84 | -------------------------------------------------------------------------------- /examples/config/vite.mock-data.2.mts: -------------------------------------------------------------------------------- 1 | import type { Plugin } from 'vite'; 2 | import { defineConfig } from 'vite'; 3 | import pluginExternal from 'vite-plugin-external'; 4 | import pluginMockData from 'vite-plugin-mock-data'; 5 | import { view } from 'vite-plugin-view'; 6 | 7 | // https://vitejs.dev/config/ 8 | export default defineConfig({ 9 | plugins: [ 10 | pluginExternal({ 11 | externals: { 12 | react: '$linkdesign.React', 13 | 'react-dom': '$linkdesign.ReactDOM', 14 | 'prop-types': '$linkdesign.PropTypes' 15 | } 16 | }) as unknown as Plugin, 17 | pluginMockData({ 18 | logLevel: 'TRACE', 19 | routes: { 20 | '/hello': 'hello', 21 | '/hello2'(req, res) { 22 | res.statusCode = 200; 23 | res.setHeader('Content-Type', 'text/html'); 24 | res.end('hello2'); 25 | }, 26 | '/hello3': { 27 | handler(req, res) { 28 | res.statusCode = 200; 29 | res.setHeader('Content-Type', 'text/html'); 30 | res.end('hello3'); 31 | } 32 | }, 33 | '/json': { 34 | handler: { hello: 1 } 35 | }, 36 | '/package.json': { 37 | file: './package.json' 38 | } 39 | } 40 | }) as unknown as Plugin, 41 | view({ 42 | engine: 'pug', 43 | engineOptions: { 44 | title: 'Vite + React + Pug', 45 | reactVersion: '16.x' 46 | } 47 | }) as unknown as Plugin 48 | ], 49 | server: { 50 | open: true 51 | }, 52 | build: { 53 | outDir: 'dist/mock-data/2', 54 | minify: false, 55 | rollupOptions: { 56 | output: { 57 | format: 'iife' 58 | } 59 | } 60 | } 61 | }); 62 | --------------------------------------------------------------------------------