我在Angular4 / Angular Material 2 / TypeScript项目中使用Webpack 3来捆绑js代码。我正在尝试基于此示例实现延迟加载:https://github.com/vsavkin/router_lazyloading 我的项目使用Angular Components和外部模板(templateUrl而不是template)。 Webpack试图将它们包含在捆绑包中,但我想将它们保留在外部。如何让Webpack停止捆绑模板?
我的Webpack配置:
"use strict";
const path = require("path");
const ngtools = require("@ngtools/webpack");
const webpack = require("webpack");
const CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin;
module.exports = {
devtool: "source-map",
context: path.resolve(__dirname, "out"),
entry: {
app: [path.resolve(__dirname, "out", "app")],
vendor: [path.resolve(__dirname, "out", "vendor")]
},
output: {
path: path.resolve(__dirname, "out", "public", "assets", "js"),
filename: "[name].js",
publicPath: "/assets/js/"
},
module: {
loaders: [
{ test: /\.js$/, exclude: /node_modules/, loader: "@ngtools/webpack" }
]
},
resolve: {
extensions: [".ts", ".js"]
},
plugins: [
new ngtools.AotPlugin({
tsConfigPath: "./tsconfig.json",
mainPath: "./app.ts"
}),
new CommonsChunkPlugin({
name: "vendor"
}),
new CommonsChunkPlugin({
async: true
})
]
};
我错过了什么?