假设我在webpack.config.js文件中使用这些设置:

output: {
    path: path.resolve(__dirname + '/dist'),
    filename: 'suman.js',
    library: 'suman',
    libraryTarget: 'var'
  },

这将创建一个包,具有此输出:

var suman =
/******/ (function(modules) { // webpackBootstrap ...

消费模块的webpack配置包括如下外部:

externals: ['suman'],

这会生成一个包含“suman”模块的包:

/***/ (function(module, exports) {

module.exports = suman;

/***/ }),

我的问题很简单:

are global variables the only way to communicate between two separately built webpack bundles?

如您所见,suman是全局变量,userland模块通过查找全局变量来获取库模块 .