我正在使用webpack来构建我的angular.js应用程序.
举个简单的例子:
app.js
var angular = require('exports?window.angular!angular'),
angularMoment = require('angular-moment');
angular.module('myApp', [angularMoment]);
角moment.js
define(['angular', 'moment'], function(angular, moment) {
// some library code
});
这里有两种导入角度的方法,带有加载器和名称.它导致角度将被注入页面两次,我在控制台中看到以下警告:
WARNING: Tried to load angular more than once.
有没有办法让webpack将两个角度的导入视为同一个模块?
我的webpack.conf.js
module.exports = {
entry: {
'app': './src/app/app.js'
},
plugins: [
new webpack.ResolverPlugin(
new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin("bower.json", ["main"])
),
new AngularPlugin()
]
};
最佳答案 一种选择是将angular作为独立脚本并将其配置为外部依赖项:
module.exports = {
external: {
'angular' : 'angular'
},
entry: {
'app': './src/app/app.js'
},
plugins: [
new webpack.ResolverPlugin(
new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin("bower.json", ["main"])
),
new AngularPlugin()
]
};