【发布时间】:2018-01-16 10:00:58
【问题描述】:
我有一个使用 webpack 3.10 编写的 AngularJS (1.6) 应用程序。我有一个入口文件 (Application.ts),它创建模块、运行它,然后将它引导到文档中。
这在第一次构建时工作正常,但是一旦我保存更改,让 webpack watch 完成它的工作然后刷新浏览器,应用程序没有引导。通过将console.log 放在我的Application.ts 文件顶部附近,很明显入口文件没有被执行。
如果我停止 webpack watch 进程并重新启动它并刷新浏览器,应用程序将成功引导。
奇怪的是,这个过去是成功的,然后突然就停止了。我忍受了一段时间,它突然又开始工作了!然后上周它又自己崩溃了。
编辑 1
所以我想我会比较两个生成的包,第一个是第一次运行 webpack 时的包,第二个是通过 webpack watch 创建的 ts 文件经过一分钟更改后更新的包。
我很惊讶这两个文件之间存在如此巨大的差异,因为我所做的只是将 protected test: Function; 更改为 protected test2: Function;。我希望这两个捆绑包实际上是相同的,而不是我刚才提到的变化?
webpack.dev.js
const webpack = require("webpack");
const merge = require("webpack-merge");
const common = require("./webpack.common");
module.exports = merge(common, {
devtool: "inline-source-map",
watchOptions: {
aggregateTimeout: 1000
},
plugins: [
new webpack.WatchIgnorePlugin([
/\.js$/,
/\.d\.ts$/
]),
]
});
webpack.common.js
const webpack = require("webpack");
const path = require("path");
const convertPathsToAliases = require("convert-tsconfig-paths-to-webpack-aliases").default;
const tsconfig = require("./tsconfig");
const aliases = convertPathsToAliases(tsconfig);
module.exports = {
entry: {
app: path.join(__dirname, "src", "Application.ts"),
vendor: [
"angular",
"angular-route",
"angular-sanitize",
"angular-paging",
"ng-redux",
"ng-file-upload",
"ng-redux-router",
"ngmap",
"toastr",
"angular-drag-and-drop-lists",
"angular-ui-bootstrap",
"redux-thunk",
"redux-logger",
"lodash"],
},
output: {
filename: "./dist/[name].hotels.bundle.js"
},
resolve: {
extensions: [".ts", ".js"],
alias: aliases
},
externals: {
jquery: "jQuery"
},
module: {
rules: [
{
test: /\.ts$/,
enforce: "pre",
loader: "tslint-loader"
},
{
test: /\.ts$/,
loader: "ts-loader",
exclude: /node_modules/
}
]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
names: ["vendor"]
})
]
}
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es2016",
"sourceMap": true,
"moduleResolution": "node",
"lib": ["es2016" ,"dom"],
"baseUrl": ".",
"paths": {
"Models": ["src/app/models/index"],
"Utilities": ["src/app/utilities"],
"App/*": ["src/app/*"]
}
}
}
【问题讨论】: