You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
163 lines
4.3 KiB
163 lines
4.3 KiB
4 weeks ago
|
import { resolve } from "path";
|
||
|
import { defineConfig, loadEnv } from "vite";
|
||
|
|
||
|
import electron from "vite-plugin-electron";
|
||
|
import renderer from "vite-plugin-electron-renderer";
|
||
|
|
||
|
import vue from "@vitejs/plugin-vue2";
|
||
|
import vueJsx from "@vitejs/plugin-vue2-jsx";
|
||
|
|
||
|
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
|
||
|
import compressPlugin from "vite-plugin-compression";
|
||
|
|
||
|
// import { visualizer } from 'rollup-plugin-visualizer';
|
||
|
|
||
|
// compress: 'gzip' | 'brotli' | 'none'
|
||
|
function configCompressPlugin(isBuild, compress) {
|
||
|
const plugins = [];
|
||
|
if (!isBuild) return plugins;
|
||
|
const compressList = compress.split(",");
|
||
|
if (compressList.includes("gzip")) {
|
||
|
plugins.push(
|
||
|
compressPlugin({
|
||
|
verbose: true,
|
||
|
disable: false,
|
||
|
threshold: 10240,
|
||
|
algorithm: "gzip",
|
||
|
ext: ".gz",
|
||
|
})
|
||
|
);
|
||
|
}
|
||
|
if (compressList.includes("brotli")) {
|
||
|
plugins.push(
|
||
|
compressPlugin({
|
||
|
verbose: true,
|
||
|
disable: false,
|
||
|
threshold: 10240,
|
||
|
algorithm: "brotliCompress",
|
||
|
ext: ".br",
|
||
|
})
|
||
|
);
|
||
|
}
|
||
|
return plugins;
|
||
|
}
|
||
|
|
||
|
function windowsPlugin(isWindows) {
|
||
|
return isWindows
|
||
|
? [
|
||
|
electron([
|
||
|
{
|
||
|
// Main-Process entry file of the Electron App.
|
||
|
entry: "electron/main.js",
|
||
|
},
|
||
|
{
|
||
|
entry: "electron/preload.js",
|
||
|
onstart(options) {
|
||
|
// Notify the Renderer-Process to reload the page when the Preload-Scripts build is complete,
|
||
|
// instead of restarting the entire Electron App.
|
||
|
options.reload();
|
||
|
},
|
||
|
},
|
||
|
]),
|
||
|
renderer(),
|
||
|
]
|
||
|
: [];
|
||
|
}
|
||
|
export default ({ mode }) => {
|
||
|
const isBuild = mode === "production"; // mode == production
|
||
|
const env = loadEnv(mode, process.cwd()); // dev
|
||
|
const isWindows = env.VITE_APP_IsWIndows === "true";
|
||
|
console.log(" env.VITE_APP_IsWIndows", isWindows, env.VITE_APP_IsWIndows);
|
||
|
console.log("env", mode, env);
|
||
|
const port = env.PORT || 9529; // dev port
|
||
|
|
||
|
return defineConfig({
|
||
|
plugins: [
|
||
|
// createVuePlugin(),
|
||
|
vue(),
|
||
|
vueJsx(),
|
||
|
createSvgIconsPlugin({
|
||
|
iconDirs: [resolve(process.cwd(), "src/icons/svg")],
|
||
|
symbolId: "icon-[dir]-[name]",
|
||
|
}),
|
||
|
...configCompressPlugin(isBuild && !isWindows, 'gzip,brotli'),
|
||
|
// visualizer(),
|
||
|
...windowsPlugin(isWindows),
|
||
|
],
|
||
|
resolve: {
|
||
|
alias: {
|
||
|
"@": resolve(__dirname, "./src"),
|
||
|
vue: "vue/dist/vue.esm.js",
|
||
|
},
|
||
|
},
|
||
|
base: "./",
|
||
|
server: {
|
||
|
host: '0.0.0.0',
|
||
|
port,
|
||
|
open: true,
|
||
|
headers: {
|
||
|
"Cross-Origin-Opener-Policy": "same-origin",
|
||
|
"Cross-Origin-Embedder-Policy": "require-corp",
|
||
|
},
|
||
|
hmr: { overlay: false },
|
||
|
proxy: {
|
||
|
"/api": {
|
||
|
target: env.VITE_APP_BASE_URL,
|
||
|
changeOrigin: true,
|
||
|
ws: true,
|
||
|
},
|
||
|
"/cc-admin": {
|
||
|
target: env.VITE_APP_BASE_URL,
|
||
|
changeOrigin: true,
|
||
|
ws: true,
|
||
|
},
|
||
|
"/pythonapi": {
|
||
|
target: env.VITE_APP_PY_URL,
|
||
|
changeOrigin: true,
|
||
|
ws: true,
|
||
|
rewrite: (path) => path.replace(/^\/pythonapi/, ""),
|
||
|
},
|
||
|
"/mxcad": {
|
||
|
target: "http://localhost:3001",
|
||
|
changeOrigin: true,
|
||
|
ws: true,
|
||
|
},
|
||
|
"/demo": {
|
||
|
target: "http://localhost:3001",
|
||
|
changeOrigin: true,
|
||
|
ws: true,
|
||
|
}
|
||
|
},
|
||
|
},
|
||
|
build: {
|
||
|
outDir: "dist",
|
||
|
assetsDir: "static",
|
||
|
// sourcemap: false,
|
||
|
// chunkSizeWarningLimit: 1000,
|
||
|
rollupOptions: {
|
||
|
output: {
|
||
|
chunkFileNames: "static/js/[name]-[hash].js",
|
||
|
entryFileNames: "static/js/[name]-[hash].js",
|
||
|
assetFileNames: "static/[ext]/[name]-[hash].[ext]",
|
||
|
// manualChunks(id) { // 静态资源分拆打包
|
||
|
// if (id.includes('node_modules')) {
|
||
|
// return id.toString().split('node_modules/')[1].split('/')[0].toString()
|
||
|
// }
|
||
|
// }
|
||
|
},
|
||
|
},
|
||
|
// minify: 'terser',
|
||
|
// terserOptions: {
|
||
|
// compress: {
|
||
|
// drop_console: isBuild, // 打包时删除log
|
||
|
// drop_debugger: isBuild, // 打包时删除debugger
|
||
|
// pure_funcs: isBuild ? ['console.log'] : []
|
||
|
// },
|
||
|
// output: {
|
||
|
// comments: isBuild // 去掉注释
|
||
|
// }
|
||
|
// }
|
||
|
},
|
||
|
});
|
||
|
};
|