我想最好加载节点包,并且只有在不存在时才加载 bower 包。
我只会按照 Webpack 站点中的建议使用节点包,但我需要加载一个仅在凉亭中的库,https://github.com/Stamplay/stamplay-js-sdk 和 https://github.com /Stamplay/angular-stamplay
尝试使用bower-webpack-plugin
我安装了https://github.com/lpiepiora/bower-webpack-plugin
但是当我运行时webpack-dev-server -d --watch
,错误会显示在 chrome 控制台中:
Uncaught TypeError: angular.module is not a function(anonymous function) @ app.js:8__webpack_require__ @ bootstrap 6cecf8d96fb5a1205f10:19(anonymous function) @ bootstrap 6cecf8d96fb5a1205f10:39__webpack_require__ @ bootstrap 6cecf8d96fb5a1205f10:19(anonymous function) @ bootstrap 6cecf8d96fb5a1205f10:39(anonymous function) @ bootstrap 6cecf8d96fb5a1205f10:39
angular.js:68Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:nomod] Module 'app' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
尝试使用 ResolverPlugin(请参阅Webpack 文档)
在 webpack.config 我添加..
plugins: [
...
, new webpack.ProvidePlugin({
Q: 'q',
store: 'store.js',
Stamplay: 'stamplay-js-sdk'
})
, new webpack.ResolverPlugin(
[
new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin("bower.json", ["main"])
], ["normal", "loader"]
)
],
....
resolve: {
root: [
path.join(__dirname, 'node_modules'),
path.join(__dirname, 'bower_components')
],
但是,就像这里提到的Stamplay
对象不正确!
尝试使用 CDN 和 angular-webpack-plugin
首先将脚本标签添加到index.html
..
其次,在 webpack.config 中添加 externals ..
externals: {
stamplay: 'Stamplay'
},
最后 ..new AngularPlugin
进入plugins
webpack.config
这种方式,但我不能使用angular-stamplay
,当我尝试时,模块出现错误stamplay
。:(