vite-plugin-jdists 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +70 -6
- package/package.json +3 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Game
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# vite-plugin-jdists
|
|
2
2
|
|
|
3
3
|
## Introduction
|
|
4
|
+
|
|
4
5
|
[](https://npmjs.com/package/vite-plugin-jdists)
|
|
5
6
|
|
|
6
7
|
A vite plugin for [jdists](https://github.com/zswang/jdists).
|
|
@@ -11,22 +12,61 @@ A vite plugin for [jdists](https://github.com/zswang/jdists).
|
|
|
11
12
|
|
|
12
13
|
``` javascript
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
viteJdistsPlugin({
|
|
16
|
+
include?: ['**/*.tsx', '**/*.ts'],
|
|
17
|
+
exclude?: ['node_modules/**', 'dist/**'],
|
|
18
|
+
/**
|
|
19
|
+
* dev 模式时删除 /* <prod> */ ${代码} /* </prod> */
|
|
20
|
+
* prod 模式时删除 /* <dev> */ ${代码} /* </dev> */
|
|
21
|
+
*/
|
|
22
|
+
remove: process.env.NODE_ENV === 'development' ? ['prod'] : ['dev'],
|
|
23
|
+
trigger?: ['release']
|
|
24
|
+
}) as PluginOption
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
INPUT:
|
|
29
|
+
|
|
30
|
+
### 场景1:只在开发环境起作用的代码, 在生产环境会被自动删除
|
|
31
|
+
|
|
32
|
+
``` javascript
|
|
33
|
+
/* <dev> */
|
|
34
|
+
let password = '123456';
|
|
35
|
+
console.log('dev');
|
|
36
|
+
/* </dev> */
|
|
37
|
+
|
|
38
|
+
/* <prod> */
|
|
39
|
+
let password = '777777';
|
|
40
|
+
console.log('prod');
|
|
41
|
+
/* </prod> */
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
OUTPUT:
|
|
46
|
+
|
|
47
|
+
``` javascript
|
|
48
|
+
// process.env.NODE_ENV === 'development'
|
|
15
49
|
|
|
16
50
|
/* <dev> */
|
|
17
51
|
let password = '123456';
|
|
18
52
|
console.log('dev');
|
|
19
53
|
/* </dev> */
|
|
20
54
|
|
|
21
|
-
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
``` javascript
|
|
58
|
+
// process.env.NODE_ENV === 'production'
|
|
22
59
|
|
|
23
60
|
/* <prod> */
|
|
24
61
|
let password = '777777';
|
|
25
62
|
console.log('prod');
|
|
26
63
|
/* </prod> */
|
|
27
64
|
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 场景2:开发环境运行时使用的代码
|
|
28
68
|
|
|
29
|
-
|
|
69
|
+
``` javascript
|
|
30
70
|
|
|
31
71
|
let password = '123456';
|
|
32
72
|
|
|
@@ -37,8 +77,26 @@ let password = '123456';
|
|
|
37
77
|
|
|
38
78
|
```
|
|
39
79
|
|
|
40
|
-
|
|
80
|
+
OUTPUT:
|
|
81
|
+
|
|
82
|
+
``` javascript
|
|
83
|
+
// process.env.NODE_ENV === 'development'
|
|
84
|
+
|
|
85
|
+
let password = '123456';
|
|
41
86
|
|
|
87
|
+
/* <dev> */
|
|
88
|
+
let password = '777777';
|
|
89
|
+
console.log('prod');
|
|
90
|
+
/* </dev> */
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
``` javascript
|
|
94
|
+
// process.env.NODE_ENV === 'production'
|
|
95
|
+
let password = '123456';
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
这样做比判断process.env.NODE_ENV更方便,也更安全。build时jdists会自动删除所有`<dev>`代码,只保留一份代码在运行时不会暴露任何给用户。
|
|
42
100
|
|
|
43
101
|
## Install
|
|
44
102
|
|
|
@@ -46,8 +104,14 @@ let password = '123456';
|
|
|
46
104
|
|
|
47
105
|
npm i -D vite-plugin-jdists
|
|
48
106
|
|
|
107
|
+
```
|
|
108
|
+
|
|
49
109
|
## Usage
|
|
50
|
-
|
|
110
|
+
|
|
111
|
+
```javascript
|
|
112
|
+
|
|
113
|
+
// vite.config.js
|
|
114
|
+
|
|
51
115
|
import { defineConfig, type PluginOption } from 'vite';
|
|
52
116
|
|
|
53
117
|
import viteJdistsPlugin from 'vite-plugin-jdists'
|
|
@@ -58,7 +122,7 @@ export default defineConfig({
|
|
|
58
122
|
viteJdistsPlugin({
|
|
59
123
|
include: ['**/*.tsx', '**/*.ts'], // 修正路径模式
|
|
60
124
|
exclude: ['node_modules/**', 'dist/**'],
|
|
61
|
-
remove: ['prod'],
|
|
125
|
+
remove: process.env.NODE_ENV === 'development' ? ['prod'] : ['dev'],
|
|
62
126
|
trigger: ['release']
|
|
63
127
|
}) as PluginOption
|
|
64
128
|
]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-jdists",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "vite plugin jdists",
|
|
5
5
|
"author": "neverland",
|
|
6
6
|
"repository": "",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"main": "dist/index.cjs.js",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "vite build",
|
|
11
|
-
"dev": "vite build --watch"
|
|
11
|
+
"dev": "vite build --watch",
|
|
12
|
+
"test": "echo \"Error: no test specified\" && exit 0"
|
|
12
13
|
},
|
|
13
14
|
"dependencies": {
|
|
14
15
|
"@rollup/pluginutils": "^5.3.0",
|
|
@@ -21,6 +22,3 @@
|
|
|
21
22
|
},
|
|
22
23
|
"homepage": "https://github.com/sbramimond/vite-plugin-jdists#readme"
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|