generated from frostime/plugin-sample-vite-solidjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
106 lines (94 loc) · 3.28 KB
/
vite.config.ts
1
2
3
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { resolve } from "path"
import { defineConfig, loadEnv } from "vite"
import { viteStaticCopy } from "vite-plugin-static-copy"
import livereload from "rollup-plugin-livereload"
import solidPlugin from 'vite-plugin-solid';
import zipPack from "vite-plugin-zip-pack";
import fg from 'fast-glob';
import vitePluginYamlI18n from './yaml-plugin';
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');
const isSrcmap = env.VITE_SOURCEMAP === 'inline';
const isDev = env.NODE_ENV === 'development';
const distDir = isDev ? "dev" : "dist";
console.log("isDev=>", isDev);
console.log("isSrcmap=>", isSrcmap);
console.log("distDir=>", distDir);
return {
resolve: {
alias: {
"@": resolve(__dirname, "src"),
}
},
plugins: [
solidPlugin({
babel: {
plugins: ['solid-styled-jsx/babel']
}
}),
vitePluginYamlI18n({
inDir: 'public/i18n',
outDir: `${distDir}/i18n`
}),
viteStaticCopy({
targets: [
{ src: "./README*.md", dest: "./" },
{ src: "./plugin.json", dest: "./" },
{ src: "./preview.png", dest: "./" },
{ src: "./icon.png", dest: "./" }
],
}),
],
define: {
"process.env.DEV_MODE": JSON.stringify(isDev),
"process.env.NODE_ENV": JSON.stringify(env.NODE_ENV)
},
build: {
outDir: distDir,
emptyOutDir: false,
minify: true,
sourcemap: isSrcmap ? 'inline' : false,
lib: {
entry: resolve(__dirname, "src/index.ts"),
fileName: "index",
formats: ["cjs"],
},
rollupOptions: {
plugins: [
...(isDev ? [
livereload(distDir),
{
name: 'watch-external',
async buildStart() {
const files = await fg([
'public/i18n/**',
'./README*.md',
'./plugin.json'
]);
for (let file of files) {
this.addWatchFile(file);
}
}
}
] : [
zipPack({
inDir: './dist',
outDir: './',
outFileName: 'package.zip'
})
])
],
external: ["siyuan", "process"],
output: {
entryFileNames: "[name].js",
assetFileNames: (assetInfo) => {
if (assetInfo.name === "style.css") {
return "index.css"
}
return assetInfo.name
},
},
},
}
}
})