【问题标题】:webpack v5 SourceMapDevToolPlugin "exclude" option not workingwebpack v5 SourceMapDevToolPlugin“排除”选项不起作用
【发布时间】:2020-10-15 00:26:00
【问题描述】:

升级到 webpack 5 后,无法通过 SourceMapDevToolPlugin 排除 vendor.js 文件进行源映射。

// webpack.config.ts - removed other config for brevity
import { Configuration } from 'webpack-dev-server';

export default (env) => {
  const config: Configuration = {};
  config.mode = 'production';
  config.entry = './entry.app.js';

  config.output = {
    path: path.join(__dirname, '/public'),
    pathinfo: true,
    filename: '[name].[fullhash].js',
    chunkFilename: '[name].[fullhash].js',
  };

  config.devtool = 'source-map';
  config.bail = true;
  config.plugins = [
    new webpack.SourceMapDevToolPlugin({
      filename: '[file].map',
      exclude: ['vendor.js'],
    }),
  ];

  config.optimization = {
    minimize: true,
    minimizer: [
      new TerserPlugin({
        parallel: false,
        sourceMap: false,
      }),
      new CssMinimizerPlugin(),
    ],
    moduleIds: 'deterministic',

    splitChunks: {
      chunks: 'all',
      maxInitialRequests: 100,
      minSize: 0,
      cacheGroups: {
        vendor: {
          name: 'vendor',
          test: /([/\\]node_modules[/\\]|[/\\]dev[/\\]vendor[/\\])/,
          chunks: 'all',
        },
      },
    },
  };

 return config;
}
// entry.app.js - removed some lines for brevity

import './horrible-asset-loader';
import './setup-for-angular';
import { runApp } from './assets/js/app';
runApp();
// horrible-asset-loader.js
// contains a lot of require statements of npm packages saved into our repository under a vendor folder. crazy i know but I don't know why this was done.

require('ng-bs-daterangepicker/dist/ng-bs-daterangepicker.min.js'); // throwing an error when building because webpack is trying to create a source map for it

// Temporary solution to bundle multiple javascript files into one. This will be replaced by ES6 import.

SourceMapDevToolPlugin 排除我迄今为止尝试过的配置:

// from https://webpack.js.org/plugins/source-map-dev-tool-plugin/#exclude-vendor-maps
exclude: ['vendor.js'] 

//from https://github.com/webpack/webpack/issues/2431
exclude: /vendor.*.*/
exclude: 'vendor'

// just me desperately trying every possible config
exclude: ['vendor']
exclude: /vendor\.[0-9a-zA-Z]\.js/
exclude: 'vendor.js'
exclude: ['vendor.[chunkhash].js']
exclude: ['vendor.[fullhash].js']

github issue link 提到了 UglifyJsPlugin 的一个问题,但我们没有使用它,所以我排除了它。

虽然如果我将config.devtool 设置为falseSourceDevToolPlugin 配置有效。

我的配置有问题吗?

更新:我想我现在明白了。看起来我真的必须根据这个例子将 devtool 设置为 false:https://webpack.js.org/plugins/source-map-dev-tool-plugin/#basic-use-case

我只是认为 devtool 应该只设置为 false 用于开发模式,因为这个注释:

如果您想在开发模式下为此插件使用自定义配置,请确保禁用默认配置。 IE。设置 devtool: false。

我说的对吗?

更新 1:是的!看起来我是对的。我应该阅读 github 问题上的其他 cmets:https://github.com/webpack/webpack/issues/2431#issuecomment-245547872 很抱歉浪费了大家的时间。

【问题讨论】:

标签: javascript source-maps webpack-5


【解决方案1】:

这是一个非常愚蠢的错误。我误解了插件的文档: https://webpack.js.org/plugins/source-map-dev-tool-plugin/#basic-use-case

devtool 设置为 false 可解决此问题。

【讨论】:

    猜你喜欢
    • 2021-08-20
    • 2019-01-11
    • 2015-07-22
    • 1970-01-01
    • 2017-01-14
    • 2021-11-22
    • 2022-11-10
    • 1970-01-01
    • 2020-06-29
    相关资源
    最近更新 更多