首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >electron-vue的ReferenceError:process is not defined解决

electron-vue的ReferenceError:process is not defined解决

作者头像
薛定喵君
发布2020-07-14 10:33:45
发布2020-07-14 10:33:45
3.4K00
代码可运行
举报
文章被收录于专栏:薛定喵君薛定喵君
运行总次数:0
代码可运行

electron-vue在Windows下面报process is not defined错误

使用electron-vue开发的时候报了如下错误

  • 运行环境
  • 解决方法
  • 测试
  • 参考资料

# 运行环境

  • node v12.16.3
  • npm 6.14.4
  • webpack v4.15.1
  • vue v2.5.16
  • vue-electron v1.0.6
  • electron v4.2.5
  • 系统 windows Server 2012 R2

# 解决方法

修改项目文件 .electron-vue目录下 - webpack.renderer.config.js - webpack.web.config.js

在两个文件的new HtmlWebpackPlugin方法内(template及minify参数之间)追加代码,最终如下所示

代码语言:javascript
代码运行次数:0
运行
复制
// webpack.web.config.js
new HtmlWebpackPlugin({
    filename: 'index.html',
    template: path.resolve(__dirname, '../src/index.ejs'),
    // ----fix process is not defined----
    templateParameters(compilation, assets, options) {
        return {
            compilation: compilation,
            webpack: compilation.getStats().toJson(),
            webpackConfig: compilation.options,
            htmlWebpackPlugin: {
            files: assets,
            options: options
            },
            process,
        };
    },
    // ----fix process is not defined----
    minify: {
    collapseWhitespace: true,
    removeAttributeQuotes: true,
    removeComments: true
    },
    nodeModules: false
}),

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

# 测试

npm run dev就可以了

# 参考资料

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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/07/12 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • # 运行环境
  • # 解决方法
  • # 测试
  • # 参考资料
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档