10

My current webpack.config file

module.exports = {
    entry: "./entry.js",
    output: {
        devtoolLineToLine: true,
        sourceMapFilename: "./bundle.js.map",
        pathinfo: true,
        path: __dirname,
        filename: "bundle.js"
    },
    module: {
        loaders: [
            { test: /\.css$/, loader: "style!css" }
        ]
    },
};

I was reading here https://webpack.github.io/docs/configuration.html and found the following:

output.sourceMapFilename

[file] is replaced by the filename of the JavaScript file.

[id] is replaced by the id of the chunk.

[hash] is replaced by the hash of the compilation.

I've added it above as you can see, but when my webpack watch runs, I don't see a map file?

How is this done?

1 Answer 1

16

There are two options here:

Using the CLI development shortcut along with your --watch option:

webpack -d --watch

or using the configuration devtool option in your webpack.config.js:

module.exports = {
    devtool: "source-map",
    entry: "./entry.js",
    output: {
        devtoolLineToLine: true,
        sourceMapFilename: "./bundle.js.map",
        pathinfo: true,
        path: __dirname,
        filename: "bundle.js"
    },
    module: {
        loaders: [
            { test: /\.css$/, loader: "style!css" }
        ]
    },
};
Sign up to request clarification or add additional context in comments.

4 Comments

Ah thanks! This worked webpack -d --watch the config tool didn't do anything until I used that command.
@LeonGaban The -d option is just a shortcut that includes, among others, the devtool one. The configuration option should work with webpack --watch.
I think this is not either/or situation. you need to have both -- '-d' command parameter and including devtool declaration along with sourceMapFilename definition in webpack.config.js
Not sure what's wrong, but nothing from the suggestions work for me. I suspect it might be because of splitting the code into chunks (e.g. main.js, vendor.js).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.