From 48154b2be9046e0f97d315374b9d2554f3e33963 Mon Sep 17 00:00:00 2001 From: John Smith Date: Wed, 9 Oct 2024 01:41:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=AC=E5=85=B1=E6=9C=8D=E5=8A=A1=E5=99=A8?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E4=B8=8D=E7=94=9F=E6=88=90source=20map?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/.env | 2 ++ frontend/.env.common_server | 3 +++ frontend/.gitignore | 1 + frontend/package.json | 1 + frontend/vue.config.js | 19 +++++++++++++++---- 5 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 frontend/.env create mode 100644 frontend/.env.common_server diff --git a/frontend/.env b/frontend/.env new file mode 100644 index 0000000..e90e223 --- /dev/null +++ b/frontend/.env @@ -0,0 +1,2 @@ +LIB_USE_CDN=false +PROD_SOURCE_MAP=true diff --git a/frontend/.env.common_server b/frontend/.env.common_server new file mode 100644 index 0000000..ae6be49 --- /dev/null +++ b/frontend/.env.common_server @@ -0,0 +1,3 @@ +NODE_ENV=production +LIB_USE_CDN=true +PROD_SOURCE_MAP=false diff --git a/frontend/.gitignore b/frontend/.gitignore index da9593d..3266748 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -5,6 +5,7 @@ node_modules # local env files .env.local .env.*.local +!.env # Log files npm-debug.log* diff --git a/frontend/package.json b/frontend/package.json index 2259c54..087de45 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -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": { diff --git a/frontend/vue.config.js b/frontend/vue.config.js index c6dfa1b..99634c7 100644 --- a/frontend/vue.config.js +++ b/frontend/vue.config.js @@ -1,7 +1,16 @@ +const { defineConfig } = require('@vue/cli-service') + // 不能用localhost,https://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 = { }) } } -} +})