go-view/vite.config.ts

68 lines
1.6 KiB
TypeScript
Raw Normal View History

2021-12-10 14:11:49 +08:00
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
2022-02-28 20:26:41 +08:00
import { resolve } from 'path'
2022-03-01 16:46:48 +08:00
import { OUTPUT_DIR, brotliSize, chunkSizeWarningLimit, terserOptions, rollupOptions } from './build/constant'
2022-02-28 20:26:41 +08:00
import viteCompression from 'vite-plugin-compression'
2022-03-24 09:19:14 +08:00
import { viteMockServe} from "vite-plugin-mock";
2021-12-10 14:11:49 +08:00
function pathResolve(dir: string) {
2022-02-28 20:26:41 +08:00
return resolve(process.cwd(), '.', dir)
2021-12-10 14:11:49 +08:00
}
export default defineConfig({
2022-02-28 20:26:41 +08:00
base: './',
2022-03-24 09:19:14 +08:00
// 路径重定向
2021-12-10 14:11:49 +08:00
resolve: {
alias: [
{
find: /\/#\//,
2022-02-28 20:26:41 +08:00
replacement: pathResolve('types') + '/'
2021-12-10 14:11:49 +08:00
},
{
find: '@',
2022-02-28 20:26:41 +08:00
replacement: pathResolve('src') + '/'
2021-12-10 14:11:49 +08:00
}
],
2022-02-28 20:26:41 +08:00
dedupe: ['vue']
2021-12-10 14:11:49 +08:00
},
2022-03-24 09:19:14 +08:00
// 全局 css 注册
2021-12-10 14:11:49 +08:00
css: {
preprocessorOptions: {
scss: {
javascriptEnabled: true,
2022-02-28 20:26:41 +08:00
additionalData: `@import "src/styles/common/style.scss";`
}
}
2021-12-10 14:11:49 +08:00
},
plugins: [
2022-02-28 20:26:41 +08:00
vue(),
2022-03-24 09:19:14 +08:00
viteMockServe({
mockPath: "/src/api/mock",
// 开发打包开关
localEnabled: true,
// 生产打包开关
prodEnabled: true,
// 打开后,可以读取 ts 文件模块。 请注意,打开后将无法监视.js 文件
supportTs: true,
// 监视文件更改
watchFiles: true,
}),
// 压缩
2022-02-28 20:26:41 +08:00
viteCompression({
verbose: true,
disable: false,
threshold: 10240,
algorithm: 'gzip',
ext: '.gz'
})
2021-12-10 14:11:49 +08:00
],
build: {
target: 'es2015',
outDir: OUTPUT_DIR,
2022-03-01 16:46:48 +08:00
terserOptions: terserOptions,
rollupOptions: rollupOptions,
brotliSize: brotliSize,
chunkSizeWarningLimit: chunkSizeWarningLimit
2022-02-28 20:26:41 +08:00
}
})