0

I am struggling with the following issue. I have a webpack plugin that is optimizing my css files. Now I want to exclude one specific file from being processed.

This is the plugin: https://github.com/NMFR/optimize-css-assets-webpack-plugin Now there is an option to specify the file pattern that should be processed: assetNameRegExp: /\.optimize\.css$/g,

Now I want to exclude one speficic file: my-stylesheet.css

I tried a lot of things and I am pretty sure that I will need some negative lookaheads, but I can't get it to work.

So far I am here: /^.*(?!my-stylesheet\.css)/ or event without the preceding characters: /^(?!my-stylesheet\.css)$/

But it will always match. What am I doing wrong?

  • whatever.scss should match (I don't know if at that point I still have scss files)

  • another/css.css should match

  • my-other-stylesheet.css should match

  • my-stylesheet.css should NOT match

Thank you so much in advance for your help. Cheers

Merc
  • 4,241
  • 8
  • 52
  • 81
  • 1
    `/^(?!my-stylesheet\.css)$/` only matches an empty string, it is equal to `^$`, you need `/^(?!my-stylesheet\.css$)/` or `/^(?!my-stylesheet\.css$).*/`. Or, if it should not end with the string: `/^(?!.*my-stylesheet\.css$)/` / `/^(?!.*my-stylesheet\.css$).*/` – Wiktor Stribiżew Nov 24 '22 at 15:47
  • Of course one finds the solution right after asking the question: this did the trick for me: https://regex101.com/r/OjtVIH/2 `/^(?!.*my-stylesheet.css).*$/` – Merc Nov 24 '22 at 15:51
  • 1
    @WiktorStribiżew your solution seems to work as well. Thank you for the quick reply! – Merc Nov 24 '22 at 15:52
  • 1
    Do not forget to escape the literal dot in the regex patterns. – Wiktor Stribiżew Nov 24 '22 at 15:54
  • Yeah true, I did that, but in my comment I forgot. Thank you. – Merc Nov 26 '22 at 13:37

0 Answers0