代码之家  ›  专栏  ›  技术社区  ›  Sam

源地图不是由网页包生成的

  •  4
  • Sam  · 技术社区  · 7 年前

    诚然,我对 source maps webpack . 我的理解是,如果我设置 devtools 在我的 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({
            'process.env': {
                'NODE_ENV': JSON.stringify('production')
            }
        }),
        new webpack.optimize.UglifyJsPlugin({
            minimize: true,
            compress: true,
            output: { comments: false }
        })
    ];
    
    var _devtool = IS_DEV ? 'eval' : '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: './components/login/login.jsx',
        home: './components/home/home.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']
        }
    }
    
    1 回复  |  直到 7 年前
        1
  •  9
  •   Cody Geisler    7 年前

    根据文件,

    使用uglifyjs网页包插件时,必须提供源地图: true选项以启用SourceMap支持。