我们正在尝试将前端版本转换为使用Brunch。这是我到目前为止的早午餐配置:

module.exports = {

  files: {
    javascripts: {
      joinTo: {
        'vendor.js': /^(?!source)/,
        'app.js': /^source/
      },
      entryPoints: {
        'source/scripts/app.jsx': 'app.js'
      }
    },
    stylesheets: {joinTo: 'core.css'},
  },

  paths: {
    watched: ['source']
  },

  modules: {
    autoRequire: {
      'app.js': ['source/scripts/app']
    }
  },

  plugins: {
    babel: {presets: ['latest', 'react']},
    postcss: {processors: [require('autoprefixer')]},
    assetsmanager: {
      copyTo: {
        'assets': ['source/resources/*']
      }
    },
    static: {
      processors: [
        require('html-brunch-static')({
          processors: [
            require('pug-brunch-static')({
              fileMatch: 'source/views/home.pug',
              fileTransform: (filename) => {
                filename = filename.replace(/\.pug$/, '.html');
                filename = filename.replace('views/', '');
                return filename;
              }
            })
          ]
        })
      ]
    }

  }

};

我将modules.autoRequire部分添加到Brunch配置中,然后开始发生以下错误。没有modules.autoRequire,我没有控制台错误,但是我的Web应用程序无法启动。运行brunch build不会导致任何错误,但是当我打开构建的网站时,我得到了错误



stacktrace的第一行将我指向vendor.js中的此函数
var require = function(name, loaderPath) {
  if (loaderPath == null) loaderPath = '/';
  var path = expandAlias(name);

  if (has.call(cache, path)) return cache[path].exports;
  if (has.call(modules, path)) return initModule(path, modules[path]);

  throw new Error("Cannot find module '" + name + "' from '" + loaderPath + "'");
};

我不确定如何继续进行构建。这个issue似乎很重要。

我该如何克服这个错误? (请随时询问其他信息。我不确定这对您有什么帮助。)

最佳答案

Brunch从package.json中定义的(特定于早午餐的)npm软件包中开始构建管道的步骤。因此,请确保包括所有需要的软件包(或删除不必要的软件包)。

参见docs for more information about how to use plugins

08-05 09:02