electron-vue 运行出现 process is not defined 错误的解决方法

2026-07-01 250 浏览 0 评论

在公司创建的 electron-vue 项目,然后回到家把代码检出,运行 npm install 安装运行环境,然后 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
}),

发布评论

发布评论前请先 登录
0 评论
点赞
收藏

评论列表 0

暂无评论