Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow removeComments to be a regex string in JSON config #255

Open
Tomalak opened this issue Sep 8, 2023 · 1 comment
Open

Allow removeComments to be a regex string in JSON config #255

Tomalak opened this issue Sep 8, 2023 · 1 comment

Comments

@Tomalak
Copy link

Tomalak commented Sep 8, 2023

Currently (v2.0.4), the removeComments module only allows Booleans, fixed strings ('safe' and 'all'), and RegExp objects.

I propose allowing regular expression strings as well, in order to be able to define a custom regex in a JSON config file.

Motivation is this heads-up notice in the Parcel bundler documentation:

Note: .htmlnanorc.js, .htmlnanorc.mjs, .htmlnanorc.cjs, htmlnano.config.js, htmlnano.config.mjs, and htmlnano.config.cjs are also supported for JavaScript-based configuration, but should be avoided when possible because it reduces the effectiveness of Parcel's caching. Use a JSON based configuration format instead.

So supporting this would enable Parcel to be more efficient when a custom regex for comment removal is employed.

The general approach to interpreting the setting within removeComments.es6 could remain the same - first check for fixed keywords like 'safe' or 'all', after that employ a regex. Except that removeType would be passed to new RegExp() instead of going through an instanceOf RegExp check, which currently limits the config file format to JS for this use case.

Future keywords or even a config object could be introduced later-on without risk of breaking anything, and existing configuration would not break, either - unless it relies on unsupported/undocumented settings silently being interpreted as 'safe'.

@maltsev
Copy link
Member

maltsev commented Sep 11, 2023

Sounds like a good option to have!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants