vite-plugin-jdists 1.0.0 → 1.0.2
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/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +18 -0
- package/dist/index.es.js +54 -32
- package/package.json +2 -1
- package/src/index.d.ts +18 -0
- package/vite.config.js +19 -3
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";const d=require("jdists"),m=require("@rollup/pluginutils");function p(c={}){const{include:f=/\.(js|ts|jsx|tsx|vue|svelte|astro|md)$/,exclude:g=[],remove:s=["debug","test"],trigger:i=["release"],config:n,...a}=c,o=m.createFilter(f,g),u=e=>Array.isArray(e)?e.join(","):e;return{name:"vite-plugin-jdists",enforce:"pre",transform(e,t){if(!o(t))return null;try{const r={fromString:!0,path:t,...a};return s&&(r.remove=u(s)),i&&(r.trigger=u(i)),n&&(r.config=n),{code:d.build(e,r),map:null}}catch{return{code:e,map:null}}},handleHotUpdate(e){const{file:t,server:r,modules:l}=e;if(o(t))return console.log(`[vite-plugin-jdists] 热更新文件: ${t}`),l}}}module.exports=p;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PluginOption } from 'vite';
|
|
2
|
+
export { PluginOption } from 'vite';
|
|
3
|
+
|
|
4
|
+
interface Options {
|
|
5
|
+
/** The types of console that needs to be removed, such as `log`、`warn`、`error`、`info`, default `log` */
|
|
6
|
+
includes?: string[] | undefined;
|
|
7
|
+
/** Don't remove the types of console these modules */
|
|
8
|
+
external?: string[] | undefined;
|
|
9
|
+
/** Don't remove the log that contains this value */
|
|
10
|
+
remove?: string[] | undefined;
|
|
11
|
+
/** Completely customize the statements that need to be removed, which will overwrite `includes` */
|
|
12
|
+
trigger?: string[] | undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** https://github.com/xiaoxian521/vite-plugin-remove-console#-configurable */
|
|
16
|
+
declare function jdists(options?: Partial<Options>): PluginOption;
|
|
17
|
+
|
|
18
|
+
export { jdists as default };
|
package/dist/index.es.js
CHANGED
|
@@ -1,33 +1,55 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createFilter } from "@rollup/pluginutils";
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
import g from "jdists";
|
|
2
|
+
import { createFilter as m } from "@rollup/pluginutils";
|
|
3
|
+
function j(f = {}) {
|
|
4
|
+
const {
|
|
5
|
+
include: c = /\.(js|ts|jsx|tsx|vue|svelte|astro|md)$/,
|
|
6
|
+
exclude: a = [],
|
|
7
|
+
remove: i = ["debug", "test"],
|
|
8
|
+
trigger: n = ["release"],
|
|
9
|
+
config: s,
|
|
10
|
+
...d
|
|
11
|
+
} = f, o = m(c, a), l = (r) => Array.isArray(r) ? r.join(",") : r;
|
|
12
|
+
return {
|
|
13
|
+
name: "vite-plugin-jdists",
|
|
14
|
+
// 强制插件在 transform 阶段运行
|
|
15
|
+
enforce: "pre",
|
|
16
|
+
/**
|
|
17
|
+
* 转换代码
|
|
18
|
+
* @param {string} code - 源代码
|
|
19
|
+
* @param {string} id - 文件路径
|
|
20
|
+
* @returns {string} 处理后的代码
|
|
21
|
+
*/
|
|
22
|
+
transform(r, t) {
|
|
23
|
+
if (!o(t))
|
|
24
|
+
return null;
|
|
25
|
+
try {
|
|
26
|
+
const e = {
|
|
27
|
+
fromString: !0,
|
|
28
|
+
path: t,
|
|
29
|
+
...d
|
|
30
|
+
};
|
|
31
|
+
return i && (e.remove = l(i)), n && (e.trigger = l(n)), s && (e.config = s), {
|
|
32
|
+
code: g.build(r, e),
|
|
33
|
+
map: null
|
|
34
|
+
};
|
|
35
|
+
} catch {
|
|
36
|
+
return {
|
|
37
|
+
code: r,
|
|
38
|
+
map: null
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
/**
|
|
43
|
+
* 处理热更新
|
|
44
|
+
* @param {Object} ctx - 热更新上下文
|
|
45
|
+
*/
|
|
46
|
+
handleHotUpdate(r) {
|
|
47
|
+
const { file: t, server: e, modules: u } = r;
|
|
48
|
+
if (o(t))
|
|
49
|
+
return console.log(`[vite-plugin-jdists] 热更新文件: ${t}`), u;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
32
52
|
}
|
|
33
|
-
export {
|
|
53
|
+
export {
|
|
54
|
+
j as default
|
|
55
|
+
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-jdists",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "vite plugin jdists",
|
|
5
5
|
"author": "neverland",
|
|
6
6
|
"repository": "",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
7
8
|
"main": "dist/index.cjs.js",
|
|
8
9
|
"scripts": {
|
|
9
10
|
"build": "vite build",
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PluginOption } from 'vite';
|
|
2
|
+
export { PluginOption } from 'vite';
|
|
3
|
+
|
|
4
|
+
interface Options {
|
|
5
|
+
/** The types of console that needs to be removed, such as `log`、`warn`、`error`、`info`, default `log` */
|
|
6
|
+
includes?: string[] | undefined;
|
|
7
|
+
/** Don't remove the types of console these modules */
|
|
8
|
+
external?: string[] | undefined;
|
|
9
|
+
/** Don't remove the log that contains this value */
|
|
10
|
+
remove?: string[] | undefined;
|
|
11
|
+
/** Completely customize the statements that need to be removed, which will overwrite `includes` */
|
|
12
|
+
trigger?: string[] | undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** https://github.com/xiaoxian521/vite-plugin-remove-console#-configurable */
|
|
16
|
+
declare function jdists(options?: Partial<Options>): PluginOption;
|
|
17
|
+
|
|
18
|
+
export { jdists as default };
|
package/vite.config.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defineConfig } from 'vite';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import fs from 'fs';
|
|
3
4
|
|
|
4
5
|
export default defineConfig({
|
|
5
6
|
build: {
|
|
@@ -7,7 +8,7 @@ export default defineConfig({
|
|
|
7
8
|
entry: path.resolve(__dirname, 'src/index.js'),
|
|
8
9
|
name: 'vitePluginJdists',
|
|
9
10
|
fileName: (format) => `index.${format}.js`,
|
|
10
|
-
formats: ['
|
|
11
|
+
formats: ['es','cjs']
|
|
11
12
|
},
|
|
12
13
|
rollupOptions: {
|
|
13
14
|
external: [
|
|
@@ -26,5 +27,20 @@ export default defineConfig({
|
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
},
|
|
29
|
-
plugins: [
|
|
30
|
-
|
|
30
|
+
plugins: [
|
|
31
|
+
{
|
|
32
|
+
name: 'copy-types',
|
|
33
|
+
closeBundle() {
|
|
34
|
+
const srcPath = path.resolve(__dirname, 'src/index.d.ts');
|
|
35
|
+
const distPath = path.resolve(__dirname, 'dist/index.d.ts');
|
|
36
|
+
|
|
37
|
+
// 确保 dist 目录存在
|
|
38
|
+
fs.mkdirSync(path.dirname(distPath), { recursive: true });
|
|
39
|
+
|
|
40
|
+
// 复制类型文件
|
|
41
|
+
fs.copyFileSync(srcPath, distPath);
|
|
42
|
+
console.log('✅ index.d.ts 已复制到 dist 目录');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
});
|