import {defineConfig, loadEnv} from 'vite'
import path from 'path'
import createVitePlugins from './vite/plugins'
const nowTime = new Date().getTime()
export default defineConfig(({mode, command}) => {
const env = loadEnv(mode, process.cwd())
const {VITE_APP_ENV} = env
return {
base: VITE_APP_ENV === 'production' ? '/' : '/',
plugins: createVitePlugins(env, command === 'build'),
resolve: {
alias: {
'~': path.resolve(__dirname, './'),
'@': path.resolve(__dirname, './src'),
UTILS: path.resolve(__dirname, './src/utils'),
},
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
},
css: {
preprocessorOptions: {
scss: {
},
},
postcss: {
plugins: [
{
postcssPlugin: 'internal:charset-removal',
AtRule: {
charset: (atRule) => {
if (atRule.name === 'charset') {
atRule.remove()
}
},
},
},
],
},
},
build: {
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('node_modules')) {
return 'vendor'
}
return null
},
chunkFileNames: ({name}) => {
if (name === 'vendor') {
return `assets/js/[name]-[hash].js`
} else {
return `assets/js/[name]-[hash]-${nowTime}.js`
}
},
entryFileNames: ({name}) => {
if (name === 'vendor') {
return `assets/js/[name]-[hash].js`
} else {
return `assets/js/[name]-[hash]-${nowTime}.js`
}
},
assetFileNames: `assets/[ext]/[name]-[hash].[ext]`,
},
},
},
}
})
重点是这个

