Preact-cli: Cannot Remove bundled hash in filename of CSS

Created on 11 Sep 2019  路  5Comments  路  Source: preactjs/preact-cli


Bug
The reason for below change is i can't update the hashed css file name is other's website every time it gets builded**

Currently filename: '[name].[contenthash:5].css' for isProd

I cannot override the above file name in preact.config.js as per below code

const cssExtractPlugin = helpers.getPluginsByName(config, "MiniCssExtractPlugin")
cssExtractPlugin.forEach(
    ({ plugin }) =>
      (plugin.options.filename = "widget.css")
  );

The above change is ignored and bundle.31cd2.css is generated as-usual

My expected behaviour is to generate widget.css

Note: If it's the usual behaviour please guide me in updating file remotely.

upstream

Most helpful comment

@RaghulXander try this:

const { plugin: cssExtractPlugin } = helpers.getPluginsByName(config, 'MiniCssExtractPlugin')[0];
cssExtractPlugin.options.moduleFilename = () => 'widget.css';
cssExtractPlugin.options.filename = 'widget.css';

It should work both in 3.0.0-rc.2 and 3.0.0-rc.5 (latest at the time of writting).

All 5 comments

Can u try with --no-esm?

Getting this error with help commands Unknown argument: esm
Cannot find esm in the help commands.

"preact-cli": "^3.0.0-rc.2",

@RaghulXander try this:

const { plugin: cssExtractPlugin } = helpers.getPluginsByName(config, 'MiniCssExtractPlugin')[0];
cssExtractPlugin.options.moduleFilename = () => 'widget.css';
cssExtractPlugin.options.filename = 'widget.css';

It should work both in 3.0.0-rc.2 and 3.0.0-rc.5 (latest at the time of writting).

Thanks @bojan88..... It worked like charm

So the thing is i need to change moduleFilename along with filename ?

@RaghulXander I guess this issue is present in mini-css-extract-plugin v0.7.0 and v0.8.0, and will be fixed in next release.
You can find out more in https://github.com/webpack-contrib/mini-css-extract-plugin/pull/430

Was this page helpful?
0 / 5 - 0 ratings