|
1 |
| -import { resolve } from "path" |
2 |
| -import { defineConfig, loadEnv } from "vite" |
3 |
| -import minimist from "minimist" |
4 |
| -import { viteStaticCopy } from "vite-plugin-static-copy" |
5 |
| -import livereload from "rollup-plugin-livereload" |
6 |
| -import { svelte } from "@sveltejs/vite-plugin-svelte" |
| 1 | +import { resolve } from "path"; |
| 2 | +import { defineConfig, loadEnv } from "vite"; |
| 3 | +import minimist from "minimist"; |
| 4 | +import { viteStaticCopy } from "vite-plugin-static-copy"; |
| 5 | +import livereload from "rollup-plugin-livereload"; |
| 6 | +import { svelte } from "@sveltejs/vite-plugin-svelte"; |
7 | 7 | import zipPack from "vite-plugin-zip-pack";
|
8 |
| -import fg from 'fast-glob'; |
| 8 | +import fg from "fast-glob"; |
9 | 9 |
|
10 |
| -const args = minimist(process.argv.slice(2)) |
11 |
| -const isWatch = args.watch || args.w || false |
12 |
| -const devDistDir = "./dev" |
13 |
| -const distDir = isWatch ? devDistDir : "./dist" |
| 10 | +const args = minimist(process.argv.slice(2)); |
| 11 | +const isWatch = args.watch || args.w || false; |
| 12 | +const devDistDir = "./dev"; |
| 13 | +const distDir = isWatch ? devDistDir : "./dist"; |
14 | 14 |
|
15 |
| -console.log("isWatch=>", isWatch) |
16 |
| -console.log("distDir=>", distDir) |
| 15 | +console.log("isWatch=>", isWatch); |
| 16 | +console.log("distDir=>", distDir); |
17 | 17 |
|
18 | 18 | export default defineConfig({
|
19 |
| - resolve: { |
20 |
| - alias: { |
21 |
| - "@": resolve(__dirname, "src"), |
22 |
| - } |
| 19 | + resolve: { |
| 20 | + alias: { |
| 21 | + "@": resolve(__dirname, "src"), |
23 | 22 | },
|
| 23 | + }, |
24 | 24 |
|
25 |
| - plugins: [ |
26 |
| - svelte(), |
| 25 | + plugins: [ |
| 26 | + svelte(), |
27 | 27 |
|
28 |
| - viteStaticCopy({ |
29 |
| - targets: [ |
30 |
| - { |
31 |
| - src: "./README*.md", |
32 |
| - dest: "./", |
33 |
| - }, |
34 |
| - { |
35 |
| - src: "./icon.png", |
36 |
| - dest: "./", |
37 |
| - }, |
38 |
| - { |
39 |
| - src: "./preview.png", |
40 |
| - dest: "./", |
41 |
| - }, |
42 |
| - { |
43 |
| - src: "./plugin.json", |
44 |
| - dest: "./", |
45 |
| - }, |
46 |
| - { |
47 |
| - src: "./src/i18n/**", |
48 |
| - dest: "./i18n/", |
49 |
| - }, |
50 |
| - ], |
51 |
| - }), |
52 |
| - ], |
| 28 | + viteStaticCopy({ |
| 29 | + targets: [ |
| 30 | + { |
| 31 | + src: "./README*.md", |
| 32 | + dest: "./", |
| 33 | + }, |
| 34 | + { |
| 35 | + src: "./icon.png", |
| 36 | + dest: "./", |
| 37 | + }, |
| 38 | + { |
| 39 | + src: "./preview.png", |
| 40 | + dest: "./", |
| 41 | + }, |
| 42 | + { |
| 43 | + src: "./plugin.json", |
| 44 | + dest: "./", |
| 45 | + }, |
| 46 | + { |
| 47 | + src: "./src/i18n/**", |
| 48 | + dest: "./i18n/", |
| 49 | + }, |
| 50 | + ], |
| 51 | + }), |
| 52 | + ], |
53 | 53 |
|
54 |
| - // https://github.com/vitejs/vite/issues/1930 |
55 |
| - // https://vitejs.dev/guide/env-and-mode.html#env-files |
56 |
| - // https://github.com/vitejs/vite/discussions/3058#discussioncomment-2115319 |
57 |
| - // 在这里自定义变量 |
58 |
| - define: { |
59 |
| - "process.env.DEV_MODE": `"${isWatch}"`, |
60 |
| - }, |
| 54 | + // https://github.com/vitejs/vite/issues/1930 |
| 55 | + // https://vitejs.dev/guide/env-and-mode.html#env-files |
| 56 | + // https://github.com/vitejs/vite/discussions/3058#discussioncomment-2115319 |
| 57 | + // 在这里自定义变量 |
| 58 | + define: { |
| 59 | + "process.env.DEV_MODE": `"${isWatch}"`, |
| 60 | + }, |
61 | 61 |
|
62 |
| - build: { |
63 |
| - // 输出路径 |
64 |
| - outDir: distDir, |
65 |
| - emptyOutDir: false, |
| 62 | + build: { |
| 63 | + // 输出路径 |
| 64 | + outDir: distDir, |
| 65 | + emptyOutDir: false, |
66 | 66 |
|
67 |
| - // 构建后是否生成 source map 文件 |
68 |
| - sourcemap: false, |
| 67 | + // 构建后是否生成 source map 文件 |
| 68 | + sourcemap: false, |
69 | 69 |
|
70 |
| - // 设置为 false 可以禁用最小化混淆 |
71 |
| - // 或是用来指定是应用哪种混淆器 |
72 |
| - // boolean | 'terser' | 'esbuild' |
73 |
| - // 不压缩,用于调试 |
74 |
| - minify: !isWatch, |
| 70 | + // 设置为 false 可以禁用最小化混淆 |
| 71 | + // 或是用来指定是应用哪种混淆器 |
| 72 | + // boolean | 'terser' | 'esbuild' |
| 73 | + // 不压缩,用于调试 |
| 74 | + minify: false, |
75 | 75 |
|
76 |
| - lib: { |
77 |
| - // Could also be a dictionary or array of multiple entry points |
78 |
| - entry: resolve(__dirname, "src/index.ts"), |
79 |
| - // the proper extensions will be added |
80 |
| - fileName: "index", |
81 |
| - formats: ["cjs"], |
82 |
| - }, |
83 |
| - rollupOptions: { |
84 |
| - plugins: [ |
85 |
| - ...( |
86 |
| - isWatch ? [ |
87 |
| - livereload(devDistDir), |
88 |
| - { |
89 |
| - //监听静态资源文件 |
90 |
| - name: 'watch-external', |
91 |
| - async buildStart() { |
92 |
| - const files = await fg([ |
93 |
| - 'src/i18n/*.json', |
94 |
| - './README*.md', |
95 |
| - './plugin.json' |
96 |
| - ]); |
97 |
| - for (let file of files) { |
98 |
| - this.addWatchFile(file); |
99 |
| - } |
100 |
| - } |
101 |
| - } |
102 |
| - ] : [ |
103 |
| - zipPack({ |
104 |
| - inDir: './dist', |
105 |
| - outDir: './', |
106 |
| - outFileName: 'package.zip' |
107 |
| - }) |
108 |
| - ] |
109 |
| - ) |
110 |
| - ], |
| 76 | + lib: { |
| 77 | + // Could also be a dictionary or array of multiple entry points |
| 78 | + entry: resolve(__dirname, "src/index.ts"), |
| 79 | + // the proper extensions will be added |
| 80 | + fileName: "index", |
| 81 | + formats: ["cjs"], |
| 82 | + }, |
| 83 | + rollupOptions: { |
| 84 | + plugins: [ |
| 85 | + ...(isWatch |
| 86 | + ? [ |
| 87 | + livereload(devDistDir), |
| 88 | + { |
| 89 | + //监听静态资源文件 |
| 90 | + name: "watch-external", |
| 91 | + async buildStart() { |
| 92 | + const files = await fg(["src/i18n/*.json", "./README*.md", "./plugin.json"]); |
| 93 | + for (let file of files) { |
| 94 | + this.addWatchFile(file); |
| 95 | + } |
| 96 | + }, |
| 97 | + }, |
| 98 | + ] |
| 99 | + : [ |
| 100 | + zipPack({ |
| 101 | + inDir: "./dist", |
| 102 | + outDir: "./", |
| 103 | + outFileName: "package.zip", |
| 104 | + }), |
| 105 | + ]), |
| 106 | + ], |
111 | 107 |
|
112 |
| - // make sure to externalize deps that shouldn't be bundled |
113 |
| - // into your library |
114 |
| - external: ["siyuan", "process"], |
| 108 | + // make sure to externalize deps that shouldn't be bundled |
| 109 | + // into your library |
| 110 | + external: ["siyuan", "process"], |
115 | 111 |
|
116 |
| - output: { |
117 |
| - entryFileNames: "[name].js", |
118 |
| - assetFileNames: (assetInfo) => { |
119 |
| - if (assetInfo.name === "style.css") { |
120 |
| - return "index.css" |
121 |
| - } |
122 |
| - return assetInfo.name |
123 |
| - }, |
124 |
| - }, |
| 112 | + output: { |
| 113 | + entryFileNames: "[name].js", |
| 114 | + assetFileNames: (assetInfo) => { |
| 115 | + if (assetInfo.name === "style.css") { |
| 116 | + return "index.css"; |
| 117 | + } |
| 118 | + return assetInfo.name; |
125 | 119 | },
|
126 |
| - } |
127 |
| -}) |
| 120 | + }, |
| 121 | + }, |
| 122 | + }, |
| 123 | +}); |
0 commit comments