Skip to content

Commit ee7d65e

Browse files
committed
feat(vite-plugin-external): externalizeDeps 支持正则表达式
1 parent 3488684 commit ee7d65e

File tree

31 files changed

+169
-115
lines changed

31 files changed

+169
-115
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ gh-pages
66
coverage
77
LICENSE
88
README.md
9-
TNPM_README.md

README_zh_CN.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# vite-plugins
22

3-
> 用简单的方式去实现 vitejs 插件。
3+
> 自定义一些平时需要的 vite 插件。
44
55
## [English](./README.md) | 中文
66

7-
插件包 | 描述
8-
-------- | -----------
9-
[vite-plugin-cp](packages/vite-plugin-cp) | 打包之后复制文件到 dist 目录
10-
[vite-plugin-external](packages/vite-plugin-external) | 排出指定模块依赖,支持开发运行时和打包后的bundle文件。
11-
[vite-plugin-hook-use](packages/vite-plugin-hook-use) | 显示`vite`插件的hook函数的使用情况。
12-
[vite-plugin-include-css](packages/vite-plugin-include-css) | 打包 css 代码到 一个 js 文件中.
13-
[vite-plugin-mock-data](packages/vite-plugin-mock-data) | 本地mock数据
14-
[vite-plugin-reverse-proxy](packages/vite-plugin-reverse-proxy) | 配合Chrome插件[XSwitch](https://chrome.google.com/webstore/detail/xswitch/idkjhjggpffolpidfkikidcokdkdaogg)将线上资源代理的本地调试。
7+
## 插件
8+
9+
* [vite-plugin-cp](packages/vite-plugin-cp) - 复制文件到指定目录。
10+
* [vite-plugin-external](packages/vite-plugin-external) - 排除指定模块依赖,支持开发运行时和打包后的bundle文件。
11+
* [vite-plugin-hook-use](packages/vite-plugin-hook-use) - 显示`vite`插件的hook函数的使用情况。
12+
* [vite-plugin-include-css](packages/vite-plugin-include-css) - 打包 css 代码到 一个 js 文件中.
13+
* [vite-plugin-mock-data](packages/vite-plugin-mock-data) - 配置本地mock数据
14+
* [vite-plugin-reverse-proxy](packages/vite-plugin-reverse-proxy) - 配合Chrome插件[XSwitch](https://chrome.google.com/webstore/detail/xswitch/idkjhjggpffolpidfkikidcokdkdaogg)将线上资源代理的本地调试。

examples/vite3-combine/vite.config.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@ export default defineConfig({
1212
build: {
1313
minify: false,
1414
lib: {
15-
entry: [
16-
'src/index.js',
17-
'src/isDate.js',
18-
'src/isNil.js',
19-
'src/isNumber.js',
20-
'src/isObject.js'
21-
],
15+
entry: 'src/index.js',
2216
formats: ['es'],
2317
fileName: '[name]'
2418
}

examples/vite3-external/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"dependencies": {
1212
"vite": "^3.2.7",
13-
"vite-plugin-external": "^4.0.2"
13+
"vite-plugin-external": "workspace:^"
1414
},
1515
"repository": "https://github.com/fengxinming/vite-plugins.git"
1616
}

examples/vite4-combine/vite.config.mjs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ export default defineConfig({
1515
build: {
1616
minify: false,
1717
lib: {
18-
entry: [
19-
'src/index.ts',
20-
'src/isAsyncFunction.ts',
21-
'src/isDate.ts',
22-
'src/isError.ts',
23-
'src/isNil.ts',
24-
'src/isNumber.ts'
25-
],
2618
formats: ['es'],
2719
fileName: '[name]'
2820
}

examples/vite5-combine/src/noop.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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;

examples/vite5-combine/vite.config.mjs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default defineConfig({
77
plugins: [
88
ts(),
99
vitePluginCombine({
10-
src: 'src/*.ts',
10+
src: ['src/*.ts', '!src/noop.ts'],
1111
target: 'src/index.ts',
1212
exports: 'default',
1313
dts: true
@@ -18,11 +18,7 @@ export default defineConfig({
1818
lib: {
1919
entry: [
2020
'src/index.ts',
21-
'src/isAsyncFunction.ts',
22-
'src/isDate.ts',
23-
'src/isError.ts',
24-
'src/isNil.ts',
25-
'src/isNumber.ts'
21+
'src/noop.ts'
2622
],
2723
formats: ['es'],
2824
fileName: '[name]'

examples/vite5-cp/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
"build": "vite build"
88
},
99
"dependencies": {
10+
"@types/node": "^20.12.5",
1011
"vite": "^5.0.2",
11-
"vite-plugin-cp": "^4.0.2"
12+
"vite-plugin-cp": "workspace:^"
1213
},
1314
"repository": "https://github.com/fengxinming/vite-plugins.git"
1415
}

examples/vite5-external/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
"build": "vite build"
1515
},
1616
"dependencies": {
17+
"@types/node": "^20.12.5",
1718
"vite": "^5.0.2",
18-
"vite-plugin-external": "^4.0.2"
19+
"vite-plugin-external": "workspace:^"
1920
},
2021
"repository": "https://github.com/fengxinming/vite-plugins.git",
2122
"engines": {
@@ -24,4 +25,4 @@
2425
"devDependencies": {
2526
"globby": "^13.2.2"
2627
}
27-
}
28+
}

examples/vite5-hook-use/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
"build": "vite build"
88
},
99
"dependencies": {
10+
"@types/node": "^20.12.5",
1011
"vite": "^5.0.2",
11-
"vite-plugin-hook-use": "^4.0.0"
12+
"vite-plugin-hook-use": "workspace:^"
1213
},
1314
"repository": "https://github.com/fengxinming/vite-plugins.git"
1415
}

examples/vite5-include-css/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
"preview": "vite preview"
1010
},
1111
"dependencies": {
12+
"@types/node": "^20.12.5",
1213
"vite": "^5.0.2",
13-
"vite-plugin-external": "^4.0.2",
14-
"vite-plugin-include-css": "^4.0.0"
14+
"vite-plugin-external": "workspace:^",
15+
"vite-plugin-include-css": "workspace:^"
1516
},
1617
"repository": "https://github.com/fengxinming/vite-plugins.git"
1718
}

examples/vite5-mock-data/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
"build": "vite build"
99
},
1010
"dependencies": {
11+
"@types/node": "^20.12.5",
1112
"vite": "^5.0.2",
12-
"vite-plugin-mock-data": "^4.0.0"
13+
"vite-plugin-mock-data": "workspace:^"
1314
},
1415
"repository": "https://github.com/fengxinming/vite-plugins.git"
1516
}

examples/vite5-reverse-proxy/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
"build": "vite build"
99
},
1010
"dependencies": {
11+
"@types/node": "^20.12.5",
1112
"vite": "^5.0.2",
12-
"vite-plugin-external": "^4.0.2",
13-
"vite-plugin-reverse-proxy": "^4.0.0"
13+
"vite-plugin-external": "workspace:^",
14+
"vite-plugin-reverse-proxy": "workspace:^"
1415
},
1516
"repository": "https://github.com/fengxinming/vite-plugins.git"
1617
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"deps": "npm run clean && pnpm install",
1111
"clean": "rm -rf node_modules ./*/*/node_modules",
1212
"eslint": "eslint --ext .js,.jsx,.ts,.tsx,.mjs --fix --ignore-path .eslintignore ./",
13-
"build": "lerna run build",
13+
"build:packages": "pnpm run -r --parallel build:lib",
14+
"build:examples": "pnpm run -r --parallel build",
1415
"prepare": "husky install",
15-
"link": "lerna link",
1616
"docs": "typedoc"
1717
},
1818
"repository": {
@@ -27,6 +27,7 @@
2727
"homepage": "https://github.com/fengxinming/vite-plugins#readme",
2828
"dependencies": {
2929
"@rollup/plugin-typescript": "^11.1.5",
30+
"@types/node": "^14.18.0",
3031
"lerna": "^6.6.2",
3132
"vite": "^4.5.0"
3233
},

packages/vite-plugin-combine/README.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
[![npm package](https://nodei.co/npm/vite-plugin-combine.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/vite-plugin-combine)
44

5-
> Copy files after building bundles. Vite >= 3.1
6-
> 打包之后复制文件
5+
> Dynamically combining files to produce a single master file. Vite >= 3.1
6+
> 动态组合文件生成一个主文件。
77
88
[![NPM version](https://img.shields.io/npm/v/vite-plugin-combine.svg?style=flat)](https://npmjs.org/package/vite-plugin-combine)
99
[![NPM Downloads](https://img.shields.io/npm/dm/vite-plugin-combine.svg?style=flat)](https://npmjs.org/package/vite-plugin-combine)
@@ -19,7 +19,7 @@ npm install vite-plugin-combine --save-dev
1919
```ts
2020
export interface Options {
2121
/**
22-
* Files prepared for merging.
22+
* Files prepared for combining.
2323
*
2424
* 准备合并的文件
2525
*/
@@ -125,21 +125,13 @@ export default defineConfig({
125125
ts(),
126126
vitePluginCombine({
127127
src: 'src/*.ts',
128-
target: 'src/index.ts', // virtual file index.ts
128+
target: 'src/index.ts',
129129
dts: true
130130
})
131131
],
132132
build: {
133133
minify: false,
134134
lib: {
135-
entry: [
136-
'src/index.ts', // virtual file index.ts
137-
'src/isAsyncFunction.ts',
138-
'src/isDate.ts',
139-
'src/isError.ts',
140-
'src/isNil.ts',
141-
'src/isNumber.ts'
142-
],
143135
formats: ['es'],
144136
fileName: '[name]'
145137
}

packages/vite-plugin-combine/dist/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ function createPlugin(opts) {
5555
let mainCode = "";
5656
return {
5757
name: "vite-plugin-combine",
58+
config(config) {
59+
var _a;
60+
const { build } = config;
61+
if (!build || !(build.lib && build.lib.entry) && !((_a = build.rollupOptions) == null ? void 0 : _a.input)) {
62+
return {
63+
build: {
64+
lib: {
65+
entry: files.concat(target)
66+
}
67+
}
68+
};
69+
}
70+
},
5871
resolveId(id) {
5972
if (id === target) {
6073
return target;

packages/vite-plugin-combine/dist/index.mjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ function createPlugin(opts) {
5454
let mainCode = "";
5555
return {
5656
name: "vite-plugin-combine",
57+
config(config) {
58+
var _a;
59+
const { build } = config;
60+
if (!build || !(build.lib && build.lib.entry) && !((_a = build.rollupOptions) == null ? void 0 : _a.input)) {
61+
return {
62+
build: {
63+
lib: {
64+
entry: files.concat(target)
65+
}
66+
}
67+
};
68+
}
69+
},
5770
resolveId(id) {
5871
if (id === target) {
5972
return target;

packages/vite-plugin-combine/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"vite": ">=3.1.0"
1818
},
1919
"scripts": {
20-
"build": "vite build",
20+
"build:lib": "vite build",
2121
"watch": "vite build --watch",
2222
"release": "npm publish"
2323
},

packages/vite-plugin-combine/src/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,19 @@ export default function createPlugin(opts: Options): Plugin {
124124
return {
125125
name: 'vite-plugin-combine',
126126

127+
config(config) {
128+
const { build } = config;
129+
if (!build || (!(build.lib && build.lib.entry) && !build.rollupOptions?.input)) {
130+
return {
131+
build: {
132+
lib: {
133+
entry: files.concat(target)
134+
}
135+
}
136+
};
137+
}
138+
},
139+
127140
resolveId(id) {
128141
if (id === target) {
129142
return target;

packages/vite-plugin-cp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"vite": ">=3.1.0"
1818
},
1919
"scripts": {
20-
"build": "vite build",
20+
"build:lib": "vite build",
2121
"watch": "vite build --watch",
2222
"release": "npm publish"
2323
},

0 commit comments

Comments
 (0)