vite-plugin-jdists 1.0.0 → 1.0.1

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.
@@ -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 jdists from "jdists";
2
- import { createFilter } from "@rollup/pluginutils";
3
- function viteJdistsPlugin(n = {}) {
4
- let { include: r = /\.(js|ts|jsx|tsx|vue|svelte|astro|md)$/, exclude: i = [], remove: a = ["debug", "test"], trigger: o = ["release"], config: s, ...c } = n, l = createFilter(r, i), u = (e) => Array.isArray(e) ? e.join(",") : e;
5
- return {
6
- name: "vite-plugin-jdists",
7
- enforce: "pre",
8
- transform(t, n) {
9
- if (!l(n)) return null;
10
- try {
11
- let r = {
12
- fromString: !0,
13
- path: n,
14
- ...c
15
- };
16
- return a && (r.remove = u(a)), o && (r.trigger = u(o)), s && (r.config = s), {
17
- code: jdists.build(t, r),
18
- map: null
19
- };
20
- } catch {
21
- return {
22
- code: t,
23
- map: null
24
- };
25
- }
26
- },
27
- handleHotUpdate(e) {
28
- let { file: t, server: n, modules: r } = e;
29
- if (l(t)) return console.log(`[vite-plugin-jdists] 热更新文件: ${t}`), r;
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 { viteJdistsPlugin as default };
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.0",
3
+ "version": "1.0.1",
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: ['cjs', 'es']
11
+ formats: ['es']
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
+ });
package/dist/index.cjs.js DELETED
@@ -1 +0,0 @@
1
- var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`jdists`);c=s(c);let l=require(`@rollup/pluginutils`);function u(e={}){let{include:t=/\.(js|ts|jsx|tsx|vue|svelte|astro|md)$/,exclude:n=[],remove:r=[`debug`,`test`],trigger:i=[`release`],config:a,...o}=e,s=(0,l.createFilter)(t,n),u=e=>Array.isArray(e)?e.join(`,`):e;return{name:`vite-plugin-jdists`,enforce:`pre`,transform(e,t){if(!s(t))return null;try{let n={fromString:!0,path:t,...o};return r&&(n.remove=u(r)),i&&(n.trigger=u(i)),a&&(n.config=a),{code:c.default.build(e,n),map:null}}catch{return{code:e,map:null}}},handleHotUpdate(e){let{file:t,server:n,modules:r}=e;if(s(t))return console.log(`[vite-plugin-jdists] 热更新文件: ${t}`),r}}}module.exports=u;