123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- import { resolve } from 'path'
- import { loadEnv } from 'vite'
- import type { UserConfig, ConfigEnv } from 'vite'
- import { createVitePlugins } from './build/vite'
- import { include, exclude } from "./build/vite/optimize"
- const root = process.cwd()
- function pathResolve(dir: string) {
- return resolve(root, '.', dir)
- }
- export default ({ command, mode }: ConfigEnv): UserConfig => {
- let env = {} as any
- const isBuild = command === 'build'
- if (!isBuild) {
- env = loadEnv((process.argv[3] === '--mode' ? process.argv[4] : process.argv[3]), root)
- } else {
- env = loadEnv(mode, root)
- }
- return {
- base: env.VITE_BASE_PATH,
- root: root,
-
- server: {
- port: env.VITE_PORT,
- host: "0.0.0.0",
- open: env.VITE_OPEN === 'true',
-
-
-
-
-
-
-
-
-
- },
-
- plugins: createVitePlugins(),
- css: {
- preprocessorOptions: {
- scss: {
- additionalData: '@import "./src/styles/variables.scss";',
- javascriptEnabled: true
- }
- }
- },
- resolve: {
- extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.scss', '.css'],
- alias: [
- {
- find: 'vue-i18n',
- replacement: 'vue-i18n/dist/vue-i18n.cjs.js'
- },
- {
- find: /\@\//,
- replacement: `${pathResolve('src')}/`
- }
- ]
- },
- build: {
- minify: 'terser',
- outDir: env.VITE_OUT_DIR || 'dist',
- sourcemap: env.VITE_SOURCEMAP === 'true' ? 'inline' : false,
-
- terserOptions: {
- compress: {
- drop_debugger: env.VITE_DROP_DEBUGGER === 'true',
- drop_console: env.VITE_DROP_CONSOLE === 'true'
- }
- }
- },
- optimizeDeps: { include, exclude }
- }
- }
|