electron-vue报错 ReferenceError: process is not defined

在使用electron-vue时,运行npm run dev出现如下错误

electron-vue报错 ReferenceError: process is not defined_第1张图片
image.png

解决方式:
找到.electron-vue/webpack.web.config.js 和.electron-vue/webpack.renderer.config.js中的HtmlWebpackPlugin,添加templateParameters,修改后如下:

  plugins: [
    new VueLoaderPlugin(),
    new MiniCssExtractPlugin({filename: 'styles.css'}),
    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
    }),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoEmitOnErrorsPlugin()
  ],

参考:
https://blog.csdn.net/Gabriel_wei/article/details/92785089

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

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