go-view/vite.config.ts

72 lines
1.7 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-07-06 14:13:27 +08:00
import { viteMockServe } from 'vite-plugin-mock'
import monacoEditorPlugin from 'vite-plugin-monaco-editor'
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({
base: '/',
2022-03-24 09:19:14 +08:00
// 路径重定向
2021-12-10 14:11:49 +08:00
resolve: {
alias: [
{
find: /\/#\//,
replacement: pathResolve('types')
2021-12-10 14:11:49 +08:00
},
{
find: '@',
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-07-06 14:13:27 +08:00
monacoEditorPlugin({
2022-07-15 00:11:42 +08:00
languageWorkers: ['editorWorkerService', 'typescript', 'json', 'html']
2022-07-06 14:13:27 +08:00
}),
2022-03-24 09:19:14 +08:00
viteMockServe({
2022-07-06 14:13:27 +08:00
mockPath: '/src/api/mock',
2022-03-24 09:19:14 +08:00
// 开发打包开关
2022-07-06 14:13:27 +08:00
localEnabled: true,
2022-03-24 09:19:14 +08:00
// 生产打包开关
prodEnabled: true,
// 打开后,可以读取 ts 文件模块。 请注意,打开后将无法监视.js 文件
supportTs: true,
// 监视文件更改
2022-07-06 14:13:27 +08:00
watchFiles: true
}),
2022-03-24 09:19:14 +08:00
// 压缩
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
}
})