Webpack与bower支持

rid*_*nsb 6 angularjs bower webpack webpack-dev-server

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

我只会按照Webpack网站中的建议使用节点包,但是我需要加载一个只有凉亭的库,https://github.com/Stamplay/stamplay-js-sdkhttps://github.com/stamplay /角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.
Run Code Online (Sandbox Code Playgroud)

尝试使用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')
    ],
Run Code Online (Sandbox Code Playgroud)

但是,就像这里提到的那样,Stamplay对象不正确!

尝试使用CDN和angular-webpack-plugin

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

其次,在webpack.config中添加外部..

externals: {
    stamplay: 'Stamplay'
},
Run Code Online (Sandbox Code Playgroud)

最后.. new AngularPlugin进入pluginswebpack.config

这样一来,worsks 我不能使用angular-stamplay,当我尝试,在模块错误stamplay冲击片雷管.:(

在此处查看此更改的分支

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

Ais*_*ngh 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-sdk然后sudo npm run build瞧!事情完成了。

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

抱歉,如果你还有别的意思。这能解决您的问题吗?