如何为WebPack创建源映射?

Leo*_*ban 6 javascript module source-maps webpack

我当前的webpack.config档案

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" }
        ]
    },
};
Run Code Online (Sandbox Code Playgroud)

我在这里阅读https://webpack.github.io/docs/configuration.html,发现以下内容:

output.sourceMapFilename

[file]被JavaScript文件的文件名替换.

[id]被块的id替换.

[hash]被编译的哈希替换.

我已经在上面添加了它,但是当我的webpack手表运行时,我看不到地图文件?

这是怎么做到的?

dre*_*cat 11

这里有两个选项:

使用CLI 开发快捷方式以及您的--watch选项:

webpack -d --watch
Run Code Online (Sandbox Code Playgroud)

或使用您的配置devtool选项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" }
        ]
    },
};
Run Code Online (Sandbox Code Playgroud)