NMFR / optimize-css-assets-webpack-plugin

A Webpack plugin to optimize \ minimize CSS assets.
MIT License
1.15k stars 69 forks source link

support for output.devtoolModuleFilenameTemplate #75

Open bholloway opened 6 years ago

bholloway commented 6 years ago

Migrating a build to Webpack 4 and the new extract css methodology.

I'm up and running so thanks to you for your efforts with this plugin.

I have always made good use of source-maps, even in production, and I was able to get this working too. Currently I am using version ^4.0.0 as followings.

{
  output: {
    ...
    devtoolModuleFilenameTemplate: templateFn,
    devtoolFallbackModuleFilenameTemplate: templateFn
  },
  ...
  optimization: {
    minimizer: [
      new OptimizeCSSAssetsPlugin({
        cssProcessorOptions: {
          map: true,
          ...
        }
      })
    ]
  }
}

Historically I have found devtoolModuleFilenameTemplate is essential for getting useful source-maps.

However it seems that this plugin bypasses devtoolModuleFilenameTemplate for extracted .css.map.

As a work around I am using an additional plugin.

new LastCallWebpackPlugin({
  assetProcessors: [{
    regExp: /\.css\.map/,
    processor: (assetName, asset) => Promise.resolve(JSON.parse(asset.source()))
      .then(obj => ...apply templateFn...)
      .then(obj => JSON.stringify(obj))
  }]
})

So I am not blocked. However is there any chance that the plugin can support devtoolModuleFilenameTemplate in future?

Or equally is this some misconfiguration on my part?

galvarez421 commented 5 years ago

This does not seem to be a misconfiguration your part. Related to #91 and https://github.com/NMFR/optimize-css-assets-webpack-plugin/issues/53#issuecomment-494830816.