From 97b1f0590763dfcfaea25b318df8e77028c530b0 Mon Sep 17 00:00:00 2001 From: npmrun <62639956+npmrun@users.noreply.github.com> Date: Thu, 29 Jul 2021 00:16:40 +0800 Subject: [PATCH] =?UTF-8?q?fixede=20bug=20=E6=B7=BB=E5=8A=A0=E5=BC=80?= =?UTF-8?q?=E5=8F=91=E8=AF=B4=E6=98=8E=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/webpack/webpack.main.config.js | 4 ++-- vite.config.ts | 2 -- 说明.md | 29 +++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 说明.md diff --git a/script/webpack/webpack.main.config.js b/script/webpack/webpack.main.config.js index 5847734..6256392 100644 --- a/script/webpack/webpack.main.config.js +++ b/script/webpack/webpack.main.config.js @@ -57,9 +57,9 @@ let mainConfig = { if (process.env.NODE_ENV !== 'production') { mainConfig.plugins.push( new webpack.DefinePlugin({ - '__static': `"${process.env.STATIC.replace(/\\/g, '\\\\')}"` + '__static': `"${join(__dirname, '../../resource/electron/static').replace(/\\/g, '\\\\')}"` }) ) } -module.exports = mainConfig \ No newline at end of file +module.exports = mainConfig diff --git a/vite.config.ts b/vite.config.ts index 6c51237..9efed90 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -8,7 +8,6 @@ import replace from '@rollup/plugin-replace'; let isDev = process.env.NODE_ENV === "development" -console.log('--->',process.env.STATIC); let plugins = [] let staticPath = isDev? '/static': 'static' @@ -17,7 +16,6 @@ plugins.push( preventAssignment: true, "__static": staticPath, "__staticVar": `"${staticPath}"` - // "__static": `file:///${process.env.STATIC.replace(/\\/g, '\\\\')}` }) ) diff --git a/说明.md b/说明.md new file mode 100644 index 0000000..739c119 --- /dev/null +++ b/说明.md @@ -0,0 +1,29 @@ +### 渲染层 + +全局替换字符 + +* `__static`: 静态资源字符串,注意没有用引号包裹,不能直接赋值 +* `__staticVar`: 静态资源字符串变量,可以赋值 + + +* 静态资源目录为根目录:`resource/electron`, 里面的东西会原封不动的复制到`dist/electron`中 + +预加载资源 +* 预加载的脚本会自动从`src/preload`直接复制到`dist/src/preload`; + +### mian层 + +全局变量 + +* `__static`: `resource/electron/static`的资源目录字符串变量,生产环境则是在`entry.js`根据此文件定位的`./static`中 + + +## 开发环境变量 +* `process.env.PORT` 开发环境时启动服务的端口,可以修改 +* `process.env.NODE_ENV` 区分是开发环境 + +## 生产环境 +* `process.env.PORT` 不需要 +* `process.env.NODE_ENV` 区分是生产环境 + +