108 lines
2.5 KiB
TypeScript
108 lines
2.5 KiB
TypeScript
![]() |
import { defineConfig, loadEnv } from 'vite'
|
||
|
import vue from '@vitejs/plugin-vue'
|
||
|
import requireTransform from 'vite-plugin-require-transform'
|
||
|
import postCssPxToRem from 'postcss-pxtorem'
|
||
|
import { createStyleImportPlugin, AndDesignVueResolve } from 'vite-plugin-style-import'
|
||
|
import { resolve } from 'path'
|
||
|
import path from 'path'
|
||
|
import type { ConfigEnv } from 'vite'
|
||
|
|
||
|
export default ({ mode }: ConfigEnv) => {
|
||
|
const root = process.cwd()
|
||
|
const ENV = loadEnv(mode, root)
|
||
|
|
||
|
console.log(`当前环境信息:`, mode)
|
||
|
console.log(`ENV:`, ENV)
|
||
|
|
||
|
return defineConfig({
|
||
|
base: ENV.VITE_BASE_URL,
|
||
|
server: {
|
||
|
host: '0.0.0.0',
|
||
|
// https: false,
|
||
|
cors: true,
|
||
|
open: true,
|
||
|
port: 9990,
|
||
|
proxy: {}
|
||
|
},
|
||
|
define: {
|
||
|
'process.env': {
|
||
|
mode: mode,
|
||
|
BASE_URL: ENV.VITE_BASE_URL,
|
||
|
API_BASE: ENV.VITE_API_BASE
|
||
|
},
|
||
|
buildTime: new Date()
|
||
|
},
|
||
|
resolve: {
|
||
|
alias: {
|
||
|
'@': '/src'
|
||
|
},
|
||
|
extensions: ['.js', '.ts', '.jsx', '.tsx', '.json']
|
||
|
},
|
||
|
optimizeDeps: {
|
||
|
include: ['kml-geojson']
|
||
|
},
|
||
|
json: {
|
||
|
namedExports: true,
|
||
|
stringify: false
|
||
|
},
|
||
|
css: {
|
||
|
preprocessorOptions: {
|
||
|
less: {
|
||
|
javascriptEnabled: true
|
||
|
},
|
||
|
scss: {
|
||
|
additionalData: `@import "@/assets/style/mixin.scss";`
|
||
|
}
|
||
|
},
|
||
|
postcss: {
|
||
|
plugins: [
|
||
|
postCssPxToRem({
|
||
|
rootValue: 80,
|
||
|
unitPrecision: 5,
|
||
|
selectorBlackList: ['ignore'],
|
||
|
propList: ['*'],
|
||
|
additionalPropList: ['*'],
|
||
|
replace: true,
|
||
|
mediaQuery: false,
|
||
|
minPixelValue: 1
|
||
|
})
|
||
|
]
|
||
|
}
|
||
|
},
|
||
|
build: {
|
||
|
outDir: path.join('./dist', ENV.VITE_BASE_URL),
|
||
|
assetsInlineLimit: 4096,
|
||
|
cssCodeSplit: true,
|
||
|
sourcemap: false,
|
||
|
commonjsOptions: {},
|
||
|
rollupOptions: {
|
||
|
input: {
|
||
|
index: path.resolve(__dirname, 'index.html')
|
||
|
}
|
||
|
},
|
||
|
manifest: false,
|
||
|
minify: 'terser',
|
||
|
terserOptions: {},
|
||
|
write: true,
|
||
|
emptyOutDir: true
|
||
|
},
|
||
|
plugins: [
|
||
|
vue(),
|
||
|
requireTransform({
|
||
|
fileRegex: /.ts$|.tsx$|.vue$/
|
||
|
}),
|
||
|
createStyleImportPlugin({
|
||
|
resolves: [AndDesignVueResolve()],
|
||
|
libs: [
|
||
|
{
|
||
|
libraryName: 'ant-design-vue',
|
||
|
esModule: true,
|
||
|
resolveStyle: (name) => {
|
||
|
return `ant-design-vue/es/${name}/style/index`
|
||
|
}
|
||
|
}
|
||
|
]
|
||
|
})
|
||
|
]
|
||
|
})
|
||
|
}
|