【问题标题】:Is there a way to load webpack bundle using requirejs require function?有没有办法使用 requirejs 的 require 函数来加载 webpack 包?
【发布时间】:2019-04-30 11:01:27
【问题描述】:

我想使用 requirejs 的 require 函数加载一个 webpack 包。 webpack 包文件正在加载,其全局变量/对象在页面上可用(如果使用 devtool 控制台访问),但没有调用 requirejs 回调函数。

// module structure that bundled with webpack
(function() {
  var module = { /* module code */ }

  define('MODULE_NAME', module);
})();

// code to load webpack bundle
var modules = ['MODULE_NAME'];
reqObject.bundles['PATH_TO_WEBPACK_BUNDLE'] = modules;

require(modules, function () {
  // NOT BEING CALLED
});

requirejs.onError = function() { debugger; }

如果调用了 requirejs 回调,我可以在其中运行应用程序引导代码。此外,不会调用 RequireJS onError 处理程序来显示任何错误。

【问题讨论】:

    标签: webpack requirejs


    【解决方案1】:

    添加以下配置以作为全局模块输出包

    输出:{ 库:未定义, 图书馆目标:'全球' }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-06
      • 1970-01-01
      • 2019-11-09
      • 2018-04-13
      • 2018-08-30
      • 2015-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多