57 lines
1.3 KiB
JavaScript
57 lines
1.3 KiB
JavaScript
import { defineConfig } from 'vite'
|
|
import uni from '@dcloudio/vite-plugin-uni'
|
|
import path from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
function resolveRootDir() {
|
|
try {
|
|
const url = typeof import.meta !== 'undefined' ? import.meta.url : ''
|
|
if (url) return path.dirname(fileURLToPath(url))
|
|
} catch (e) {
|
|
}
|
|
try {
|
|
if (typeof __dirname !== 'undefined') return __dirname
|
|
} catch (e) {
|
|
}
|
|
return process.cwd()
|
|
}
|
|
|
|
const rootDir = resolveRootDir()
|
|
|
|
export default defineConfig({
|
|
base: '/h5/',
|
|
plugins: [uni()],
|
|
// 微信小程序的代码压缩器不支持 ES2020 语法(?? / ?.),
|
|
// 在构建阶段统一降级到 ES2017,避免上传时「代码压缩」报 Unexpected token ?
|
|
build: {
|
|
target: ['es2017', 'chrome61', 'safari11', 'firefox60'],
|
|
},
|
|
esbuild: {
|
|
target: 'es2017',
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
'@': rootDir,
|
|
},
|
|
},
|
|
server: {
|
|
host: '127.0.0.1',
|
|
port: 4403,
|
|
strictPort: true,
|
|
proxy: {
|
|
'/proxy-api': {
|
|
target: 'http://127.0.0.1:9000',
|
|
changeOrigin: true,
|
|
rewrite: (path) => path.replace(/^\/proxy-api/, ''),
|
|
},
|
|
},
|
|
},
|
|
css: {
|
|
preprocessorOptions: {
|
|
scss: {
|
|
silenceDeprecations: ['legacy-js-api', 'color-functions', 'import'],
|
|
},
|
|
},
|
|
},
|
|
})
|