Electron-vue报错Webpack ReferenceError:process is not defined

报错 Webpack ReferenceError: process is not defined

最新重新安装electron-vue后,使用yarn安装项目,结果一直报错。起初以为是yarn的问题,使用npm安装也发现同样的问题。Google后发现应该是node版本问题,将node降为Node11可以正常工作。

解决方案

修改.electron-vue/webpack.web.config.js和.electron-vue/webpack.renderer.config.js文件的HtmlWebpackPlugin,添加templateParameters,修改后如下:

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: false
    }),
    

参考

https://github.com/SimulatedGREG/electron-vue/issues/871

你可能感兴趣的:(Electron-vue报错Webpack ReferenceError:process is not defined)