我正在学Webpack.我用Angular制作了一个应用程序,我使用templateCache在一个js文件中生成所有我的html视图,而不是在App中.它很酷但是Webpack的工作:
entry: {
app: ["bootstrap-webpack!./bootstrap.config.js",'./app/app.js'],vendor: ['angular','bootstrap','angular-ui-router','oclazyload']
},output: {
path: path.join(__dirname,"dist"),filename: '/bundle.js'
},plugins: [
new webpack.optimize.CommonsChunkPlugin(
/* chunkName= */ "vendor",/* filename= */ "/vendor.bundle.js"),
这是我的webpack配置的一部分.结果我得到目录“dist”与“bundle.js”&& “vendor.bundle.js”和index.html.之后,我启动服务器,我的应用程序说它不能GET视图.为什么? :(我知道我所有的意见都必须捆绑,并且应该在“dist”目录下可用.
解决方法
我根本不使用templateCache.由于Angular指令也接受一个模板作为字符串,我只需要()模板与
html-loader.
function MyDirective() {
return {
restrict: "E",replace: true,template: require("./MyDirective.html")
};
}
// in your webpack.config.js
module.exports = {
module: {
loaders: [
{ test: /\.html$/,loaders: ["html"] }
]
}
}