公共服务器前端不生成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 # local env files
.env.local .env.local
.env.*.local .env.*.local
!.env
# Log files # Log files
npm-debug.log* npm-debug.log*

View File

@ -5,6 +5,7 @@
"scripts": { "scripts": {
"serve": "vue-cli-service serve", "serve": "vue-cli-service serve",
"build": "vue-cli-service build", "build": "vue-cli-service build",
"build_common_server": "vue-cli-service build --mode common_server",
"lint": "vue-cli-service lint" "lint": "vue-cli-service lint"
}, },
"dependencies": { "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 // 不能用localhosthttps://forum.dfinity.org/t/development-workflow-quickly-test-code-modifications/1793/21
const API_BASE_URL = 'http://127.0.0.1:12450' 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: { devServer: {
proxy: { proxy: {
'/api': { '/api': {
@ -16,12 +25,14 @@ module.exports = {
}, },
} }
}, },
productionSourceMap: toBool(process.env.PROD_SOURCE_MAP),
chainWebpack: config => { chainWebpack: config => {
const APP_VERSION = `v${process.env.npm_package_version}` const APP_VERSION = `v${process.env.npm_package_version}`
const LIB_USE_CDN = toBool(process.env.LIB_USE_CDN)
const ENV = { const ENV = {
APP_VERSION, APP_VERSION,
LIB_USE_CDN: true, LIB_USE_CDN,
} }
config.plugin('define') config.plugin('define')
.tap(args => { .tap(args => {
@ -33,7 +44,7 @@ module.exports = {
return args return args
}) })
if (ENV.LIB_USE_CDN) { if (LIB_USE_CDN) {
config.externals({ config.externals({
'element-ui': 'ELEMENT', 'element-ui': 'ELEMENT',
lodash: '_', lodash: '_',
@ -44,4 +55,4 @@ module.exports = {
}) })
} }
} }
} })