package.json overrides
Using json-merger's syntax you have powerful ways to customize configs without JavaScript directly in your package.json files. There can be some really exotic cases tho. This is a place to collect some of these solutions.
All samples should be placed inside { "mhy": { HERE } } in your package.json file.
Extend .npmignore with custom file names
.npmignore with custom file names"npmignore": {
"root": {
"$concat": [
"/test",
"/ci.sh",
"/.gitbook"
]
}
}babel: Deep customization
babel: Deep customizationNote: Babel support was replaced by SWC, but the example is still helpful.
Change
preset-envto producecommonjsmodulesAdd
module.exportsstatements to each module for default exports (from Babel v7 it is not being added anymore by default)Remove
regenerator-plugin, it doesn't needed innode.
"babel": {
"production": {
"presets": [
{
"$match": {
"query": "$[?(@[0].includes('preset-env'))]",
"value": [
{
"$match": {
"index": 1,
"value": {
"modules": "commonjs",
"targets": {
"node": true,
"esmodules": true
}
}
}
}
]
}
}
],
"plugins": [
{
"$prepend": {
"$expression": "$params.require.resolve('babel-plugin-add-module-exports')"
}
},
{
"$match": {
"query": "$[?(@.includes('regenerator'))]",
"value": {
"$remove": true
}
}
}
]
}
}Webpack: Some customization
Webpack: Some customizationGenerate
index.phpfile instead ofindex.html(in this casehtml-webpack-pluginis the first in the plugins array).Change regex for ignored modules from watch. This exact example is useful when working with locally linked npm modules and you want to recompile on it's changes also.
"webpack": {
"production": {
"plugins": [{
"$expression": "Object.assign($targetProperty.options, {filename : 'index.php'})"
}]
},
"development": {
"watchOptions": {
"ignored": [
"node_modules.(?!(my-module-.*)).*"
]
}
}
}Jest: Load extra environment setup file
Jest: Load extra environment setup file"jest": {
"development": {
"setupFilesAfterEnv": {
"$concat": [
"./test-setup.js"
]
}
}
}Last updated
Was this helpful?