使用webpack和CommonsChunkPlugin生成AMD模块

ahz*_*ahz 8 amd webpack

我正在开发多个插件到一个系统,加载这些插件作为AMD模块(带requirejs).插件编写为ES6模块并使用webpack打包(output.libraryTarget ='amd').到目前为止,一切都按预期工作.

但插件共享了很多捆绑在每个条目中的常用代码.我试图使用CommonsChunkPluginwebpack插件但是初始块包含的代码不是AMD模块.然而,仍然可以正确地生成在普通卡盘上中继的其他入口点.另外文档说在一个页面上有多个初始块(使用JSONp运行时)并不是一个好主意 - 另一个插件作者可能会使用相同的方法.

有没有办法以AMD兼容的方式优化这个用例?在我看来,这是一个错误,CommonsChunkPlugin因为初始条目不是AMD(但它的代码在插件环境中加载是不安全的)...是否有我缺少的配置?

Kre*_*zot 1

I'm not quite sure that understand you correctly. But if you want to build your bundle as AMD module, than you must config it as a library:

...
output: {
    ...
    library: true,
    libraryTarget: 'umd'
},
Run Code Online (Sandbox Code Playgroud)