如何使用Webpack.ProvidePlugin加载用户定义的全局对象?
我知道您可以使用ProvidePlugin将每个jQuery注入到使用它的模块中如何使用Webpack.ProvidePlugin加载用户定义的全局对象?,webpack,Webpack,我知道您可以使用ProvidePlugin将每个jQuery注入到使用它的模块中 plugins: [ new Webpack.ProvidePlugin({ $: "jquery", jQuery: "jquery", }) ], 在全局空间中有一个我自己的实用程序模块,我想使用ProvidePlugin来加载,就像jQuery一样,我该怎么做 plugins: [ new webpack.ProvidePlugin({
plugins: [
new Webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
})
],
在全局空间中有一个我自己的实用程序模块,我想使用ProvidePlugin来加载,就像jQuery一样,我该怎么做
plugins: [
new webpack.ProvidePlugin({
'mtUtilities': '../Presentation/Base/Default/js/source/_common/mtUtilities.js'
})
],
上述代码将导致路径错误。程序找不到“mtUtilities”,因为路径是相对的,所以它是错误的。如何修复它 下面的方法应该有效
new webpack.ProvidePlugin({
'mtUtilities': __dirname + '/../Presentation/Base/Default/js/source/_common/mtUtilities.js'
})
如果我没记错的话,你只需要在你的html中包含你的
mtUtilities.js
,标签和配置就像插件:[new webpack.ProvidePlugin({'mtUtilities':'mtUtilities'),