【问题标题】:Javascript not executing after webpack watchwebpack watch 后 Javascript 未执行
【发布时间】: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/*"]
        }
    }
}

【问题讨论】:

    标签: angularjs webpack


    【解决方案1】:

    重启我的机器可以解决问题。

    我知道这是一个非常令人失望的答案,但是这个“错误”偶尔会随机出现在 watch 将不再正确构建捆绑包的地方。每次重启都能解决问题。

    【讨论】:

    • 哇。我没有看到那会发生。很高兴你让它再次工作!
    • 我的手表有一个完全不同的问题,重启也为我解决了这个问题,很奇怪。
    猜你喜欢
    • 2020-09-12
    • 2021-10-28
    • 2020-08-12
    • 1970-01-01
    • 1970-01-01
    • 2017-11-09
    • 1970-01-01
    相关资源
    最近更新 更多