vite.config.js配置项
配置@路径
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
resolve: {
alias: {
"@": "/src",
},
},
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
const { resolve } = require('path')
import { viteMockServe } from "vite-plugin-mock"
const localEnabled = process.env.USE_MOCK || false;
const prodEnabled = process.env.USE_CHUNK_MOCK || false;
export default () => defineConfig({
plugins: [
vue(),
viteMockServe({
mockPath: "./src/server/mock",
localEnabled: localEnabled,
prodEnabled: prodEnabled,
injectCode: `
import { setupProdMockServer } from './mockProdServer';
setupProdMockServer();
`,
logger: false,
supportTs:false
})
],
optimizeDeps: {
entries: [],
include: ['axios'],
exclude:['your-package-name']
},
publicDir: "public",
base: './',
assetsInclude: "",
logLevel: "info",
clearScreen:true,
resolve: {
alias: [
{ find: '@', replacement: resolve(__dirname, 'src') }
],
conditions: [],
extensions:['.mjs','.js','.ts','.jsx','.tsx','.json']
},
css: {
modules: { },
postcss: {
},
preprocessorOptions:{
scss: {
additionalData:`$injectedColor:orange;`
}
}
},
json: {
namedExports: true,
stringify:false
},
esbuild: {
jsxFactory: "h",
jsxFragment: "Fragment",
jsxInject:`import Vue from 'vue'`
},
server: {
host: "localhost",
https: false,
cors: true,
open: true,
port: "9000",
strictPort: false,
force: true,
hmr: false,
watch: {
ignored:["!**/node_modules/your-package-name/**"]
},
proxy: {
'/api': {
target: "https://xxxx.com/",
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '')
}
}
},
build: {
target: "modules",
outDir: "dist",
assetsDir: "assets",
assetsInlineLimit: 4096,
cssCodeSplit: true,
sourcemap: false,
rollupOptions: {
},
commonjsOptions: {
},
lib: {
},
manifest: false,
minify: "terser",
terserOptions: {
},
write: true,
emptyOutDir: true,
brotliSize: true,
chunkSizeWarningLimit: 500
},
ssr: {
external: [],
noExternal: [
]
}
})