支持 Bower 的 Webpack

Webpack with bower support

我是否希望优先加载节点包,只有在不存在时才加载 bower 包。

I would just use the node package only as recommended in Webpack site, but I need to load a library that is just in bower, https://github.com/Stamplay/stamplay-js-sdk and 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 docs

在 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')
    ],

但是,就像提到 here 一样,Stamplay 对象不正确!

尝试使用 CDN 和 angular-webpack-plugin

首先将脚本标签添加到index.html..

其次,在webpack.config..

中添加外部
externals: {
    stamplay: 'Stamplay'
},

最后 .. new AngularPlugin 进入 plugins webpack.config

这样,工作 但是 我不能使用 angular-stamplay,当我尝试时,模块 stamplay apper 出现错误。 :(

查看带有 this change here

的分支

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

好的,尝试了来自 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-sdk 然后 sudo npm run build 瞧!完成了。

在与 webpack-dev-server -d --watch 相同的 npm run start 上,我得到 http://localhost:8080/webpack-dev-server/ 控制台说

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