公共服务器前端不生成source map

This commit is contained in:
John Smith 2024-10-09 01:41:33 +08:00
parent 06e5481574
commit 48154b2be9
5 changed files with 22 additions and 4 deletions

2
frontend/.env Normal file
View File

@ -0,0 +1,2 @@
LIB_USE_CDN=false
PROD_SOURCE_MAP=true

View File

@ -0,0 +1,3 @@
NODE_ENV=production
LIB_USE_CDN=true
PROD_SOURCE_MAP=false

1
frontend/.gitignore vendored
View File

@ -5,6 +5,7 @@ node_modules
# local env files
.env.local
.env.*.local
!.env
# Log files
npm-debug.log*

View File

@ -5,6 +5,7 @@
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"build_common_server": "vue-cli-service build --mode common_server",
"lint": "vue-cli-service lint"
},
"dependencies": {

View File

@ -1,7 +1,16 @@
const { defineConfig } = require('@vue/cli-service')
// 不能用localhosthttps://forum.dfinity.org/t/development-workflow-quickly-test-code-modifications/1793/21
const API_BASE_URL = 'http://127.0.0.1:12450'
module.exports = {
function toBool(val) {
if (typeof val === 'string') {
return ['false', 'no', 'off', '0', ''].indexOf(val.toLowerCase()) === -1
}
return Boolean(val)
}
module.exports = defineConfig({
devServer: {
proxy: {
'/api': {
@ -16,12 +25,14 @@ module.exports = {
},
}
},
productionSourceMap: toBool(process.env.PROD_SOURCE_MAP),
chainWebpack: config => {
const APP_VERSION = `v${process.env.npm_package_version}`
const LIB_USE_CDN = toBool(process.env.LIB_USE_CDN)
const ENV = {
APP_VERSION,
LIB_USE_CDN: true,
LIB_USE_CDN,
}
config.plugin('define')
.tap(args => {
@ -33,7 +44,7 @@ module.exports = {
return args
})
if (ENV.LIB_USE_CDN) {
if (LIB_USE_CDN) {
config.externals({
'element-ui': 'ELEMENT',
lodash: '_',
@ -44,4 +55,4 @@ module.exports = {
})
}
}
}
})