allow cjs config files on type module projects #8253
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
↪️ Pull Request
Allow plugins with
.js
config files to also work with a.cjs
extension.If you have a project with
"type": "module"
then currently it is impossible to have a javascript config file for a plugin. Either you get a error telling yourequire
isn't allowed using modules, or if you use modules you get an error telling you modules can't be used withrequire
. If you use acjs
file you get a JSON parse error.This PR allows
loadConfig
to load acjs
file asjs
file instead of trying to load it as ajson
file.It also updates all plugins that accept a js config file to also accept a cjs config file.
Also see previously reported #6830
💻 Examples
For example if you use the pug transformer, you can now have a config file called:
pug.config.cjs
.Previously it would only allow
pug.config.js
🚨 Test instructions
Create a project with
"type": "module"
in the package.json.Attempt to use a javascript config file with, for example, a pug template.
If the
.pugrc.js
is renamed.pugrc.cjs
this will now work without an error.✔️ PR Todo