目录

解决 Electron-Vue 报错:Webpack ReferenceError: process is not defined

网上找了几种方式,让修改 webpack.renderer.config.jswebpack..config.js 都不太好使,应该是由于不同的版本造成的。这里给出一种我目前(2020-10-19)配置的最新环境,可以解决的方案:

解决方案地址:https://github.com/SimulatedGREG/electron-vue/issues/871#issuecomment-564302194

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>vest</title>
    <% if (htmlWebpackPlugin.options.nodeModules) { %>
      <!-- Add `node_modules/` to global paths so `require` works properly in development -->
      <script>
        require('module').globalPaths.push('<%= htmlWebpackPlugin.options.nodeModules.replace(/\\/g, '\\\\') %>')
      </script>
    <% } %>
  </head>
  <body>
    <div id="app"></div>
    <!-- Set `__static` path to static files in production -->
    <%  if (!require('process').browser) { %>
      <script>
        if (process.env.NODE_ENV !== 'development') window.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
      </script>
    <% } %>

    <!-- webpack builds are automatically injected -->
  </body>
</html>

以上代码,覆盖到 index.ejs 文件即可。

运行效果

上一篇:«

下一篇: »


评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注