Allow removeComments to be a regex string in JSON config
Tomalak opened this issue · comments
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
, andhtmlnano.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'
.
Sounds like a good option to have!