Thursday, 11 May 2017

Dynamically update webpack entry

I have a single webpack.Compiler instance in my Node.js app which must be called to run on different entry files, which are dynamically generated. This is my compiler instance:

webpack({
    entry: "initialEntryFile.ts",
    module: {
        loaders: [
            {
                loader: "ts-loader",
                test: /\.ts$/,
            },
        ],
    },
    output: {
        filename: "compiled_filename.js",
        path: "path/",
    },
    cache: false,
    resolve: {
        extensions: [".webpack.js", ".web.js", ".ts", ".js"],
    },
});

In my app, before each webpack.run(), I update the entry option: webpack.options.entry = "new_entry_file.ts";

The problem is that even the webpack.options gets updated, when it runs it looks for the old entry (initialEntryFile.ts). I'm running the latest Webpack (2.5.1) and I even tried the dynamic entry as explained in the docs (https://webpack.js.org/configuration/entry-context/#dynamic-entry).



via Stingus

No comments:

Post a Comment