获取源地图

时间:2017-12-11 21:57:05

标签: webpack source-maps

我真的很难让源地图工作。当我运行我的应用程序时,我在控制台中看到错误 - 见下文: enter image description here

当我点击fineUploaderTest-bundle.js:1链接时,我得不到任何代码 - 请参阅下文: enter image description here

在该窗口的底部,注意它显示为:

  

从fineUploaderTest-bundle.js

映射的源代码

我的Webpack版本是2.7.0,这是webpack.config.js文件:

var IS_DEV = false;

var webpack = require('webpack');
var path = require("path");

// Define plugins needed for production and dev cases
var _pluginsDev = [
    new webpack.ProvidePlugin({
        'fetch': 'imports-loader?this=>global!exports-loader?global.fetch!whatwg-fetch',
        moment: 'moment',
        ps: 'perfect-scrollbar'
    }),

];
var _pluginsProd = [
    new webpack.ProvidePlugin({
        'fetch': 'imports-loader?this=>global!exports-loader?global.fetch!whatwg-fetch',
        moment: 'moment',
        ps: 'perfect-scrollbar'
    }),
    new webpack.DefinePlugin({ // Minimizer, removing multiple occurances of imports et.c
        'process.env': {
            'NODE_ENV': JSON.stringify('production')
        }
    }),
    new webpack.optimize.UglifyJsPlugin({
        minimize: true,
        compress: true,
        sourceMap: true,
        output: { comments: false }
    })
];

var _devtool = IS_DEV ? 'eval' : 'inline-cheap-module-source-map';
var _plugins = IS_DEV ? _pluginsDev : _pluginsProd;
var _fileName = IS_DEV ? "./build/[name]-bundle.js" : "./dist/[name]-bundle.js";

var _bundles = {
    login: './UI/components/login/login.jsx',
    fineUploaderTest: './UI/components/test.jsx'
};

module.exports = {
    entry: _bundles,
    output: {
        path: path.resolve(__dirname, "wwwroot"),
        publicPath: "/",
        filename: _fileName
    },
    devtool: _devtool,
    plugins: _plugins,
    module: {
        rules: [
            {
                test: /\.jsx?$/,
                exclude: /(node_modules|bower_components)/,
                use: {
                    loader: "babel-loader",
                    options: {
                        presets: ['es2015', 'stage-2', 'stage-0', 'react']
                    }
                }
            }
        ]
    },
    resolve: {
        extensions: ['.js', '.jsx']
    }
}

我在这里做错了什么?

2 个答案:

答案 0 :(得分:3)

你是如何运行webpack的?我假设在生产模式下你也使用-p标志?

在生产模式下,Webpack不会输出inline-cheap-module-source-map类型的源地图(参考:https://webpack.js.org/configuration/devtool/)。

要在生产模式下获得某些输出,我还建议您为inline-cheap-module-source-map切换source-map

答案 1 :(得分:0)

您可以尝试devtool的其他值。我通常在制作中使用source-map。看起来您inline-cheap-module-source-map使用IS_DEV = false时可能不准确

有关生产中建议的选项,请参阅here