🔧 ci: 更新 vite 打包脚本
This commit is contained in:
parent
4aee720da5
commit
591cf2e95e
10 changed files with 146 additions and 135 deletions
106
vite.config.ts
106
vite.config.ts
|
@ -1,6 +1,5 @@
|
|||
import { resolve } from "path"
|
||||
import { defineConfig, loadEnv } from "vite"
|
||||
import minimist from "minimist"
|
||||
import { viteStaticCopy } from "vite-plugin-static-copy"
|
||||
import livereload from "rollup-plugin-livereload"
|
||||
import { svelte } from "@sveltejs/vite-plugin-svelte"
|
||||
|
@ -9,13 +8,15 @@ import fg from 'fast-glob';
|
|||
|
||||
import vitePluginYamlI18n from './yaml-plugin';
|
||||
|
||||
const args = minimist(process.argv.slice(2))
|
||||
const isWatch = args.watch || args.w || false
|
||||
const devDistDir = "dev"
|
||||
const distDir = isWatch ? devDistDir : "dist"
|
||||
const env = process.env;
|
||||
const isSrcmap = env.VITE_SOURCEMAP === 'inline';
|
||||
const isDev = env.NODE_ENV === 'development';
|
||||
|
||||
console.log("isWatch=>", isWatch)
|
||||
console.log("distDir=>", distDir)
|
||||
const outputDir = isDev ? "dev" : "dist";
|
||||
|
||||
console.log("isDev=>", isDev);
|
||||
console.log("isSrcmap=>", isSrcmap);
|
||||
console.log("outputDir=>", outputDir);
|
||||
|
||||
export default defineConfig({
|
||||
resolve: {
|
||||
|
@ -29,92 +30,61 @@ export default defineConfig({
|
|||
|
||||
vitePluginYamlI18n({
|
||||
inDir: 'public/i18n',
|
||||
outDir: `${distDir}/i18n`
|
||||
outDir: `${outputDir}/i18n`
|
||||
}),
|
||||
|
||||
viteStaticCopy({
|
||||
targets: [
|
||||
{
|
||||
src: "./README*.md",
|
||||
dest: "./",
|
||||
},
|
||||
{
|
||||
src: "./plugin.json",
|
||||
dest: "./",
|
||||
},
|
||||
{
|
||||
src: "./preview.png",
|
||||
dest: "./",
|
||||
},
|
||||
{
|
||||
src: "./icon.png",
|
||||
dest: "./",
|
||||
}
|
||||
{ src: "./README*.md", dest: "./" },
|
||||
{ src: "./plugin.json", dest: "./" },
|
||||
{ src: "./preview.png", dest: "./" },
|
||||
{ src: "./icon.png", dest: "./" }
|
||||
],
|
||||
}),
|
||||
],
|
||||
|
||||
// https://github.com/vitejs/vite/issues/1930
|
||||
// https://vitejs.dev/guide/env-and-mode.html#env-files
|
||||
// https://github.com/vitejs/vite/discussions/3058#discussioncomment-2115319
|
||||
// 在这里自定义变量
|
||||
define: {
|
||||
"process.env.DEV_MODE": `"${isWatch}"`,
|
||||
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
|
||||
"process.env.DEV_MODE": JSON.stringify(isDev),
|
||||
"process.env.NODE_ENV": JSON.stringify(env.NODE_ENV)
|
||||
},
|
||||
|
||||
build: {
|
||||
// 输出路径
|
||||
outDir: distDir,
|
||||
outDir: outputDir,
|
||||
emptyOutDir: false,
|
||||
|
||||
// 构建后是否生成 source map 文件
|
||||
sourcemap: isWatch ? 'inline' : false,
|
||||
|
||||
// 设置为 false 可以禁用最小化混淆
|
||||
// 或是用来指定是应用哪种混淆器
|
||||
// boolean | 'terser' | 'esbuild'
|
||||
// 不压缩,用于调试
|
||||
minify: !isWatch,
|
||||
minify: true,
|
||||
sourcemap: isSrcmap ? 'inline' : false,
|
||||
|
||||
lib: {
|
||||
// Could also be a dictionary or array of multiple entry points
|
||||
entry: resolve(__dirname, "src/index.ts"),
|
||||
// the proper extensions will be added
|
||||
fileName: "index",
|
||||
formats: ["cjs"],
|
||||
},
|
||||
rollupOptions: {
|
||||
plugins: [
|
||||
...(
|
||||
isWatch ? [
|
||||
livereload(devDistDir),
|
||||
{
|
||||
//监听静态资源文件
|
||||
name: 'watch-external',
|
||||
async buildStart() {
|
||||
const files = await fg([
|
||||
'public/i18n/**',
|
||||
'./README*.md',
|
||||
'./plugin.json'
|
||||
]);
|
||||
for (let file of files) {
|
||||
this.addWatchFile(file);
|
||||
}
|
||||
...(isDev ? [
|
||||
livereload(outputDir),
|
||||
{
|
||||
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'
|
||||
})
|
||||
]
|
||||
)
|
||||
}
|
||||
] : [
|
||||
zipPack({
|
||||
inDir: './dist',
|
||||
outDir: './',
|
||||
outFileName: 'package.zip'
|
||||
})
|
||||
])
|
||||
],
|
||||
|
||||
// make sure to externalize deps that shouldn't be bundled
|
||||
// into your library
|
||||
external: ["siyuan", "process"],
|
||||
|
||||
output: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue