127 lines
3.3 KiB
TypeScript
127 lines
3.3 KiB
TypeScript
|
|
import { resolve } from 'path';
|
||
|
|
import { loadEnv } from 'vite';
|
||
|
|
import vueJsx from '@vitejs/plugin-vue-jsx';
|
||
|
|
// import legacy from '@vitejs/plugin-legacy';
|
||
|
|
import Components from 'unplugin-vue-components/vite';
|
||
|
|
import { VantResolver } from 'unplugin-vue-components/resolvers';
|
||
|
|
import { viteMockServe } from 'vite-plugin-mock';
|
||
|
|
import DefineOptions from 'unplugin-vue-define-options/vite';
|
||
|
|
import vue from '@vitejs/plugin-vue';
|
||
|
|
import checker from 'vite-plugin-checker';
|
||
|
|
import type { UserConfig, ConfigEnv } from 'vite';
|
||
|
|
|
||
|
|
const CWD = process.cwd();
|
||
|
|
|
||
|
|
export default ({ command, mode }: ConfigEnv): UserConfig => {
|
||
|
|
// 环境变量
|
||
|
|
const { VITE_DROP_CONSOLE } = loadEnv(mode, CWD);
|
||
|
|
|
||
|
|
const isBuild = command === 'build';
|
||
|
|
|
||
|
|
console.log(VITE_DROP_CONSOLE);
|
||
|
|
|
||
|
|
return {
|
||
|
|
base: 'https://images.health.ufutx.com/dp',
|
||
|
|
esbuild: {
|
||
|
|
// pure: ['console.log'],
|
||
|
|
},
|
||
|
|
|
||
|
|
resolve: {
|
||
|
|
alias: [
|
||
|
|
{
|
||
|
|
find: '@',
|
||
|
|
replacement: resolve(__dirname, './src'),
|
||
|
|
},
|
||
|
|
],
|
||
|
|
},
|
||
|
|
plugins: [
|
||
|
|
vue(),
|
||
|
|
DefineOptions(), // https://github.com/sxzz/unplugin-vue-define-options
|
||
|
|
vueJsx({}),
|
||
|
|
Components({
|
||
|
|
resolvers: [VantResolver()],
|
||
|
|
}),
|
||
|
|
viteMockServe({
|
||
|
|
ignore: /^_/,
|
||
|
|
mockPath: 'mock',
|
||
|
|
localEnabled: !isBuild,
|
||
|
|
prodEnabled: isBuild,
|
||
|
|
logger: true,
|
||
|
|
injectCode: `
|
||
|
|
import { setupProdMockServer } from '../mock/_createProductionServer';
|
||
|
|
|
||
|
|
setupProdMockServer();
|
||
|
|
`,
|
||
|
|
}),
|
||
|
|
// https://github.com/fi3ework/vite-plugin-checker
|
||
|
|
checker({
|
||
|
|
typescript: true,
|
||
|
|
// vueTsc: true,
|
||
|
|
eslint: {
|
||
|
|
lintCommand: 'eslint "./src/**/*.{.vue,ts,tsx}"', // for example, lint .ts & .tsx
|
||
|
|
},
|
||
|
|
}),
|
||
|
|
],
|
||
|
|
css: {
|
||
|
|
preprocessorOptions: {
|
||
|
|
less: {
|
||
|
|
modifyVars: {},
|
||
|
|
javascriptEnabled: true,
|
||
|
|
},
|
||
|
|
scss: {
|
||
|
|
additionalData: `@import "src/styles/vw-rem/_util.scss";
|
||
|
|
@import "src/styles/vw-rem/_border.scss";
|
||
|
|
@import "src/styles/func.scss";`,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
// TODO 构建包含@charset问题 https://github.com/vitejs/vite/issues/5833
|
||
|
|
// postcss: {
|
||
|
|
// plugins: [
|
||
|
|
// {
|
||
|
|
// postcssPlugin: 'internal:charset-removal',
|
||
|
|
// AtRule: {
|
||
|
|
// charset: (atRule) => {
|
||
|
|
// if (atRule.name === 'charset') {
|
||
|
|
// atRule.remove();
|
||
|
|
// }
|
||
|
|
// },
|
||
|
|
// },
|
||
|
|
// },
|
||
|
|
// ],
|
||
|
|
// },
|
||
|
|
},
|
||
|
|
server: {
|
||
|
|
port: 8080,
|
||
|
|
hmr: false,
|
||
|
|
proxy: {
|
||
|
|
'/api': {
|
||
|
|
// 免费的在线REST API
|
||
|
|
target: 'http://jsonplaceholder.typicode.com',
|
||
|
|
changeOrigin: true,
|
||
|
|
rewrite: (path) => path.replace(/^\/api/, ''),
|
||
|
|
},
|
||
|
|
},
|
||
|
|
},
|
||
|
|
optimizeDeps: {
|
||
|
|
include: ['vant', '@vant/touch-emulator'],
|
||
|
|
exclude: ['vue-demi'],
|
||
|
|
},
|
||
|
|
build: {
|
||
|
|
rollupOptions: {
|
||
|
|
output: {
|
||
|
|
chunkFileNames: `assets/[name].[hash].js`,
|
||
|
|
entryFileNames: `assets/[name].[hash].js`,
|
||
|
|
assetFileNames: `assets/[name].[hash].[ext]`,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
minify: 'terser',
|
||
|
|
terserOptions: {
|
||
|
|
compress: {
|
||
|
|
// drop_debugger: true,
|
||
|
|
drop_console: false,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
},
|
||
|
|
};
|
||
|
|
};
|