Getting source maps working
Asked Answered
S

2

9

I'm really struggling to get source map to work. When I run my app, I'm seeing an error in the console -- see below: enter image description here

When I click the fineUploaderTest-bundle.js:1 link, I get no code whatsoever -- see below: enter image description here

At the bottom of that window, notice that it reads:

source mapped from fineUploaderTest-bundle.js

My Webpack version is 2.7.0 and here's the webpack.config.js file:

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']
    }
}

What am I doing wrong here?

Sheepish answered 11/12, 2017 at 21:57 Comment(1)
Does webpack throw any errors when creating the bundle? You can use the argument --display-error-details to view a more verbose output when running webpack.Highkey
I
3

How are you running webpack? I assume in production mode you are also using the -p flag?

Webpack will not output a source-map of type inline-cheap-module-source-map when in production mode (ref: https://webpack.js.org/configuration/devtool/).

To get some output in production mode i'd also recommend switching inline-cheap-module-source-map for source-map.

Indite answered 21/12, 2017 at 15:44 Comment(0)
T
0

You might try another value for devtool. I usually use source-map in production. It looks like you're using inline-cheap-module-source-map when IS_DEV = false, which may not be as accurate

See here for the suggested options in production.

Taeniafuge answered 20/12, 2017 at 20:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.