2022-07-03 02:38:58 +08:00
|
|
|
|
import { resolve } from 'path';
|
2022-01-01 01:31:04 +08:00
|
|
|
|
import { ConfigEnv, loadEnv, UserConfig } from 'vite';
|
|
|
|
|
import vue from '@vitejs/plugin-vue';
|
|
|
|
|
import vueJsx from '@vitejs/plugin-vue-jsx';
|
|
|
|
|
import legacy from '@vitejs/plugin-legacy';
|
|
|
|
|
import { ElementPlusResolver, VantResolver } from 'unplugin-vue-components/resolvers';
|
|
|
|
|
import AutoImport from 'unplugin-auto-import/vite';
|
|
|
|
|
import Components from 'unplugin-vue-components/vite';
|
|
|
|
|
import WindiCSS from 'vite-plugin-windicss';
|
2022-07-03 02:38:58 +08:00
|
|
|
|
import checker from 'vite-plugin-checker';
|
|
|
|
|
import DefineOptions from 'unplugin-vue-define-options/vite';
|
2021-05-04 21:54:05 +08:00
|
|
|
|
|
2022-01-01 01:31:04 +08:00
|
|
|
|
const CWD = process.cwd();
|
2021-05-04 21:54:05 +08:00
|
|
|
|
|
2022-01-01 01:31:04 +08:00
|
|
|
|
const prefix = `monaco-editor/esm/vs`;
|
2021-05-26 22:15:13 +08:00
|
|
|
|
|
2021-05-12 11:53:17 +08:00
|
|
|
|
// https://cn.vitejs.dev/config/
|
|
|
|
|
export default ({ mode }: ConfigEnv): UserConfig => {
|
2021-05-04 21:54:05 +08:00
|
|
|
|
// 环境变量
|
2022-01-01 01:31:04 +08:00
|
|
|
|
const { VITE_BASE_URL } = loadEnv(mode, CWD);
|
2021-05-04 21:54:05 +08:00
|
|
|
|
return {
|
2021-07-04 17:04:10 +08:00
|
|
|
|
base: VITE_BASE_URL, // 设置打包路径
|
2021-05-04 21:54:05 +08:00
|
|
|
|
css: {
|
|
|
|
|
modules: {
|
2022-01-01 01:31:04 +08:00
|
|
|
|
localsConvention: 'camelCase', // 默认只支持驼峰,修改为同时支持横线和驼峰
|
|
|
|
|
},
|
|
|
|
|
preprocessorOptions: {
|
|
|
|
|
scss: {
|
|
|
|
|
charset: false,
|
|
|
|
|
},
|
|
|
|
|
less: {
|
|
|
|
|
charset: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
// TODO 构建包含@charset问题 https://github.com/vitejs/vite/issues/5833
|
2022-07-03 02:38:58 +08:00
|
|
|
|
// charset: false,
|
2022-01-01 01:31:04 +08:00
|
|
|
|
postcss: {
|
|
|
|
|
plugins: [
|
|
|
|
|
{
|
|
|
|
|
postcssPlugin: 'internal:charset-removal',
|
|
|
|
|
AtRule: {
|
|
|
|
|
charset: (atRule) => {
|
|
|
|
|
if (atRule.name === 'charset') {
|
|
|
|
|
atRule.remove();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
2021-05-04 21:54:05 +08:00
|
|
|
|
},
|
|
|
|
|
plugins: [
|
|
|
|
|
vue(),
|
|
|
|
|
vueJsx(),
|
|
|
|
|
WindiCSS(),
|
2022-07-03 02:38:58 +08:00
|
|
|
|
// https://github.com/sxzz/unplugin-vue-define-options
|
|
|
|
|
DefineOptions(),
|
2021-05-20 09:02:51 +08:00
|
|
|
|
legacy({
|
2022-01-01 01:31:04 +08:00
|
|
|
|
targets: ['defaults', 'not IE 11'],
|
|
|
|
|
}),
|
2022-07-03 02:38:58 +08:00
|
|
|
|
// https://github.com/antfu/unplugin-auto-import#readme
|
2022-01-01 01:31:04 +08:00
|
|
|
|
AutoImport({
|
2022-01-16 16:21:27 +08:00
|
|
|
|
include: [
|
|
|
|
|
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
|
|
|
|
|
/\.vue$/,
|
|
|
|
|
/\.vue\?vue/, // .vue
|
|
|
|
|
/\.md$/, // .md
|
|
|
|
|
],
|
|
|
|
|
dts: true,
|
|
|
|
|
imports: ['vue', 'vue-router'],
|
2021-05-20 09:02:51 +08:00
|
|
|
|
}),
|
2022-01-01 01:31:04 +08:00
|
|
|
|
Components({
|
2022-01-16 16:21:27 +08:00
|
|
|
|
dts: true,
|
2022-01-01 01:31:04 +08:00
|
|
|
|
resolvers: [ElementPlusResolver(), VantResolver()],
|
2021-05-04 21:54:05 +08:00
|
|
|
|
}),
|
2022-07-03 02:38:58 +08:00
|
|
|
|
// https://github.com/fi3ework/vite-plugin-checker
|
|
|
|
|
checker({
|
|
|
|
|
typescript: true,
|
|
|
|
|
// vueTsc: true,
|
|
|
|
|
eslint: {
|
|
|
|
|
lintCommand: 'eslint "./src/**/*.{.vue,ts,tsx}"', // for example, lint .ts & .tsx
|
|
|
|
|
},
|
|
|
|
|
}),
|
2021-05-04 21:54:05 +08:00
|
|
|
|
],
|
|
|
|
|
resolve: {
|
2022-01-01 01:31:04 +08:00
|
|
|
|
alias: [
|
|
|
|
|
{
|
|
|
|
|
find: '@',
|
|
|
|
|
replacement: resolve(__dirname, './src'),
|
|
|
|
|
},
|
|
|
|
|
],
|
2021-05-04 21:54:05 +08:00
|
|
|
|
},
|
2021-05-06 00:35:05 +08:00
|
|
|
|
build: {
|
2022-01-01 01:31:04 +08:00
|
|
|
|
cssCodeSplit: true, // 如果设置为false,整个项目中的所有 CSS 将被提取到一个 CSS 文件中
|
|
|
|
|
sourcemap: false, // 构建后是否生成 source map 文件。如果为 true,将会创建一个独立的 source map 文件
|
|
|
|
|
target: 'modules', // 设置最终构建的浏览器兼容目标。默认值是一个 Vite 特有的值——'modules' 还可设置为 'es2015' 'es2016'等
|
|
|
|
|
chunkSizeWarningLimit: 550, // 单位kb 打包后文件大小警告的限制 (文件大于此此值会出现警告)
|
|
|
|
|
assetsInlineLimit: 4096, // 单位字节(1024等于1kb) 小于此阈值的导入或引用资源将内联为 base64 编码,以避免额外的 http 请求。设置为 0 可以完全禁用此项。
|
|
|
|
|
minify: 'terser', // 'terser' 相对较慢,但大多数情况下构建后的文件体积更小。'esbuild' 最小化混淆更快但构建后的文件相对更大。
|
|
|
|
|
terserOptions: {
|
|
|
|
|
compress: {
|
|
|
|
|
drop_console: true, // 生产环境去除console
|
|
|
|
|
drop_debugger: true, // 生产环境去除debugger
|
|
|
|
|
},
|
|
|
|
|
},
|
2021-05-06 00:35:05 +08:00
|
|
|
|
rollupOptions: {
|
|
|
|
|
input: {
|
|
|
|
|
main: resolve(__dirname, 'index.html'),
|
2022-01-01 01:31:04 +08:00
|
|
|
|
preview: resolve(__dirname, 'preview/index.html'),
|
2021-05-26 22:15:13 +08:00
|
|
|
|
},
|
|
|
|
|
output: {
|
|
|
|
|
manualChunks: {
|
|
|
|
|
jsonWorker: [`${prefix}/language/json/json.worker`],
|
|
|
|
|
cssWorker: [`${prefix}/language/css/css.worker`],
|
|
|
|
|
htmlWorker: [`${prefix}/language/html/html.worker`],
|
|
|
|
|
tsWorker: [`${prefix}/language/typescript/ts.worker`],
|
2022-01-01 01:31:04 +08:00
|
|
|
|
editorWorker: [`${prefix}/editor/editor.worker`],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2021-05-06 00:35:05 +08:00
|
|
|
|
},
|
2021-05-04 21:54:05 +08:00
|
|
|
|
optimizeDeps: {
|
2022-01-16 16:21:27 +08:00
|
|
|
|
include: ['@vueuse/core', 'element-plus', 'vant', 'lodash-es', 'vuedraggable'],
|
2021-05-04 21:54:05 +08:00
|
|
|
|
},
|
|
|
|
|
server: {
|
2021-07-05 11:51:03 +08:00
|
|
|
|
host: '0.0.0.0',
|
2021-05-26 22:15:13 +08:00
|
|
|
|
port: 10086, // 设置服务启动端口号
|
2021-05-04 21:54:05 +08:00
|
|
|
|
open: false, // 设置服务启动时是否自动打开浏览器
|
2021-07-04 17:04:10 +08:00
|
|
|
|
cors: true, // 允许跨域
|
2021-05-04 21:54:05 +08:00
|
|
|
|
|
2021-07-04 17:04:10 +08:00
|
|
|
|
// 设置代理,根据项目实际情况配置
|
|
|
|
|
proxy: {
|
|
|
|
|
'/api': {
|
2022-01-16 16:21:27 +08:00
|
|
|
|
target: 'https://nest-api.buqiyuan.site/api/admin/',
|
2021-07-04 17:04:10 +08:00
|
|
|
|
changeOrigin: true,
|
|
|
|
|
secure: false,
|
2022-01-01 01:31:04 +08:00
|
|
|
|
rewrite: (path) => path.replace('/api/', '/'),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
};
|