Mac OS 下Electron-vue打包的一些坑

aries 发表于 2021-07-16 17 次浏览 标签 : Electron

一、一般的高版本的 node, 大于12的版本时候。初步运行 electron-vue 项目时候会报错!

新建项目并运行:
npm install -g vue-cli
vue init simulatedgreg/electron-vue my-project
cd my-project
npm install
npm run dev
报下面错误:
ERROR in Template execution failed: ReferenceError: process is not defined
ERROR in   ReferenceError: process is not defined
index.ejs:102
/Users/codeman/github/my-project/src/index.ejs:102:2
index.ejs:107 module.exports
/Users/codeman/github/my-project/src/index.ejs:107:3
index.js:284
[my-project]/[html-webpack-plugin]/index.js:284:18

只有npm run dev的时候会提示process is not defined

解决办法是:
.electron-vue/webpack.renderer.config.js.electron-vue/webpack.web.config.js文件中找到HtmlWebpackPlugin代码段并更改为如下代码:

new HtmlWebpackPlugin({
      filename: 'index.html',
      template: path.resolve(__dirname, '../src/index.ejs'),
      templateParameters(compilation, assets, options) {
        return {
          compilation: compilation,
          webpack: compilation.getStats().toJson(),
          webpackConfig: compilation.options,
          htmlWebpackPlugin: {
            files: assets,
            options: options
          },
          process,
        };
      },
      minify: {
        collapseWhitespace: true,
        removeAttributeQuotes: true,
        removeComments: true
      },
      nodeModules: process.env.NODE_ENV !== 'production'
        ? path.resolve(__dirname, '../node_modules')
        : false
    }),

二、在初步使用 electron-builder 编译 electron-vue 项目时候会报错(PS:一般出现在 MacOS 下)

Error: Exit code: 2. Command failed: /usr/bin/perl /private/var/folders/mj/n34f_bp95zq2_1fwll3bq70m0000gn/T/t-51hskU/1-dmgProperties.pl
Can't locate Mac/Memory.pm in @INC (you may need to install the Mac:: Memory module) (@INC contains: /Library/Perl/5.18/darwin-thread-multi-2level /Library/Perl/5.18 /Network/Library/Perl/5.18/darwin-thread-multi-2level /Network/Library/Perl/5.18 /Library/Perl/Updates/5.18.4 /System/Library/Perl/5.18/darwin-thread-multi-2level /System/Library/Perl/5.18 /System/Library/Perl/Extras/5.18/darwin-thread-multi-2level /System/Library/Perl/Extras/5.18 .) at /private/var/folders/mj/n34f_bp95zq2_1fwll3bq70m0000gn/T/t-51hskU/1-dmgProperties.pl line 4.
BEGIN failed--compilation aborted at /private/var/folders/mj/n34f_bp95zq2_1fwll3bq70m0000gn/T/t-51hskU/1-dmgProperties.pl line 4.
解决办法:

升级你的 electron-builder 依赖包

npm install electron-builder@latest -D

0条评论

如需评论,请填写表单。
换一个

记住我的信息