89 lines
2.2 KiB
JavaScript
89 lines
2.2 KiB
JavaScript
import { defineConfig } from "vite";
|
|
import vue from "@vitejs/plugin-vue";
|
|
// import requireTransform from "vite-plugin-require-transform";
|
|
// 如果编辑器提示 path 模块找不到,则可以安装一下 @types/node -> npm i @types/node -D
|
|
import { resolve } from "path";
|
|
import prerender from 'vite-plugin-prerender'
|
|
import nodePolyfills from 'rollup-plugin-polyfill-node';
|
|
|
|
// https://vitejs.dev/config/
|
|
export default defineConfig({
|
|
plugins: [
|
|
vue(),
|
|
// requireTransform({
|
|
// fileRegex: /.js$|.vue$/,
|
|
// }),
|
|
],
|
|
|
|
resolve: {
|
|
alias: {
|
|
'@' : resolve(__dirname, 'src'),
|
|
process: "process/browser",
|
|
stream: "stream-browserify",
|
|
zlib: "browserify-zlib",
|
|
util: 'util',
|
|
web3: resolve(__dirname, 'node_modules/web3/dist/web3.min.js')
|
|
},
|
|
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
|
|
},
|
|
base: "./", // 设置打包路径
|
|
build: {
|
|
// 打包输出目录
|
|
outDir: 'dist',
|
|
// 打包文件名
|
|
assetsDir: 'static',
|
|
// 静态资源引用路径
|
|
assetsPublicPath: '/',
|
|
sourcemap: false,
|
|
// 是否开启压缩
|
|
minify: 'terser',
|
|
// 分离代码
|
|
// splitChunks: {},
|
|
// 环境变量
|
|
env: {
|
|
BASE_URL: process.env.VITE_API_BASE_URL
|
|
},
|
|
rollupOptions: {
|
|
plugins: [nodePolyfills()],
|
|
},
|
|
commonjsOptions: {
|
|
transformMixedEsModules: true,
|
|
},
|
|
chunkSizeWarningLimit: 1500,
|
|
terserOptions: {
|
|
compress: {
|
|
drop_console: true, // 去除console.log语句
|
|
drop_debugger: true, // 去除debugger语句
|
|
},
|
|
},
|
|
},
|
|
envPrefix:"VUE_APP_",
|
|
optimizeDeps: {
|
|
esbuildOptions: {
|
|
define: {
|
|
global: "globalThis",
|
|
},
|
|
plugins: [
|
|
]
|
|
}
|
|
},
|
|
define: {
|
|
'process.env': process.env
|
|
},
|
|
server: {
|
|
port: 4000, // 设置服务启动端口号
|
|
open: false, // 设置服务启动时是否自动打开浏览器
|
|
cors: true, // 允许跨域
|
|
hmr:true,
|
|
// 设置代理,根据我们项目实际情况配置
|
|
proxy: {
|
|
'/api': {
|
|
target: process.env.VITE_API_BASE_URL, // 将 /api 开头的请求代理到该地址
|
|
changeOrigin: true,
|
|
secure: false,
|
|
rewrite: (path) => path.replace('/api/', '/')
|
|
}
|
|
}
|
|
},
|
|
});
|