6

我想最好加载节点包,并且只有在不存在时才加载 bower 包。

我只会按照 Webpack 站点中的建议使用节点包,但我需要加载一个仅在凉亭中的库,https://github.com/Stamplay/stamplay-js-sdkhttps://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进入pluginswebpack.config

这种方式,我不能使用angular-stamplay,当我尝试时,模块出现错误stamplay。:(

在此处查看具有此更改的分支

完整的项目在这里:https ://github.com/Ridermansb/webpackBowerStarter

4

1 回答 1

2

好的,从 git https://github.com/Ridermansb/webpackBowerStarter尝试了您的项目

正如在https://github.com/lpiepiora/bower-webpack-plugin/issues/20中提到的那样,我也遇到了这个Cannot resolve module 'stamplay-js-sdk'问题,然后在 webpackBowerStarter 目录中我做了bower install stamplay-js-sdksudo npm run build瞧!它完成了。

npm run start这与webpack-dev-server -d --watch我得到http://localhost:8080/webpack-dev-server/一样 http://localhost:8080/webpack-dev-server/ 控制台说 在此处输入图像描述

对不起,如果你的意思是别的。这能解决您的问题吗?

于 2015-11-05T19:48:23.383 回答