我从 npm 安装 ngRoute ,我的webpack默认加载default.js
webpack.config.js
'use strict';
var path = require('path'),
webpack = require("webpack"),
AngularPlugin = require('angular-webpack-plugin');
module.exports = {
resolve: {
root: [path.join(__dirname, "bower_components")]
},
plugins: [
new webpack.ResolverPlugin(
[new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin("bower.json", ["main"])],
["normal", "loader"]
),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"windows.jQuery": "jquery",
_: "underscore"
}),
new AngularPlugin()
],
entry: {
all: "./app/assets/javascript/default",
},
output: {
path: __dirname + '/dist/assets/javascript',
filename: "[name].bundle.js",
chunkFilename: "[id].bundle.js"
},
}
default.js
// default.js
'use strict';
require('angular-route');
require('./angularLoad')();
angularLoad.js
// angularLoad.js
module.exports = function () {
var app = angular.module('myApp', ['ngRoute']);
app.controller('ctroe', function(){
console.log("aaaaaaaaaaaa");
});
};
当我运行webpack时,收到错误消息:
找不到模块:错误:无法解析模块' ngRoute'在....
角度注入时出现此错误。有什么建议吗?感谢大家。 :)
答案 0 :(得分:3)
您可以像这样设置ngRoute
到angular-route
的别名:
resolve: {
alias: {
'ngRoute': 'angular-route'
}
}