customize-cra
Advanced tools
Comparing version 0.2.13 to 0.2.14
86
index.js
@@ -46,3 +46,3 @@ const flow = require("lodash.flow"); | ||
return babelLoader; | ||
} | ||
}; | ||
@@ -91,3 +91,3 @@ const addBabelPlugin = plugin => config => { | ||
return config; | ||
} | ||
}; | ||
@@ -185,5 +185,6 @@ const addWebpackPlugin = plugin => config => { | ||
const lessModuleRegex = /\.module\.less$/; | ||
const localIdentName = loaderOptions.localIdentName || "[path][name]__[local]--[hash:base64:5]"; | ||
const localIdentName = | ||
loaderOptions.localIdentName || "[path][name]__[local]--[hash:base64:5]"; | ||
const getLessLoader = (cssOptions) => { | ||
const getLessLoader = cssOptions => { | ||
return [ | ||
@@ -232,17 +233,22 @@ mode === "dev" | ||
// Insert less-loader as the penultimate item of loaders (before file-loader) | ||
loaders.splice(loaders.length - 1, 0, { | ||
test: lessRegex, | ||
exclude: lessModuleRegex, | ||
use: getLessLoader({ | ||
importLoaders: 2 | ||
}), | ||
sideEffects: mode === "prod" | ||
}, { | ||
test: lessModuleRegex, | ||
use: getLessLoader({ | ||
importLoaders: 2, | ||
modules: true, | ||
localIdentName: localIdentName | ||
}) | ||
}); | ||
loaders.splice( | ||
loaders.length - 1, | ||
0, | ||
{ | ||
test: lessRegex, | ||
exclude: lessModuleRegex, | ||
use: getLessLoader({ | ||
importLoaders: 2 | ||
}), | ||
sideEffects: mode === "prod" | ||
}, | ||
{ | ||
test: lessModuleRegex, | ||
use: getLessLoader({ | ||
importLoaders: 2, | ||
modules: true, | ||
localIdentName: localIdentName | ||
}) | ||
} | ||
); | ||
@@ -278,4 +284,4 @@ return config; | ||
cacheGroups: { | ||
default: false, | ||
}, | ||
default: false | ||
} | ||
}; | ||
@@ -290,3 +296,3 @@ | ||
// Useful when trying to offload libs to CDN | ||
const addWebpackExternals = (externalDeps) => config => { | ||
const addWebpackExternals = externalDeps => config => { | ||
config.externals = { | ||
@@ -299,18 +305,22 @@ ...config.externals, | ||
const addPostcssPlugins = (plugins) => config => { | ||
const addPostcssPlugins = plugins => config => { | ||
const rules = config.module.rules.find(rule => Array.isArray(rule.oneOf)) | ||
.oneOf; | ||
rules.forEach(r => r.use && r.use.forEach(u => { | ||
if (u.options && u.options.ident === "postcss") { | ||
if (!u.options.plugins) { | ||
u.options.plugins = () => [...plugins]; | ||
} | ||
if (u.options.plugins) { | ||
const originalPlugins = u.options.plugins; | ||
u.options.plugins = () => [...originalPlugins(), ...plugins]; | ||
} | ||
} | ||
})); | ||
rules.forEach( | ||
r => | ||
r.use && | ||
r.use.forEach(u => { | ||
if (u.options && u.options.ident === "postcss") { | ||
if (!u.options.plugins) { | ||
u.options.plugins = () => [...plugins]; | ||
} | ||
if (u.options.plugins) { | ||
const originalPlugins = u.options.plugins; | ||
u.options.plugins = () => [...originalPlugins(), ...plugins]; | ||
} | ||
} | ||
}) | ||
); | ||
return config; | ||
} | ||
}; | ||
@@ -326,3 +336,3 @@ // This will remove the CRA plugin that prevents to import modules from | ||
const addTslintLoader = (options) => config => { | ||
const addTslintLoader = options => config => { | ||
config.module.rules.unshift({ | ||
@@ -332,3 +342,3 @@ test: /\.(ts|tsx)$/, | ||
options, | ||
enforce: "pre", | ||
enforce: "pre" | ||
}); | ||
@@ -364,3 +374,3 @@ return config; | ||
removeModuleScopePlugin, | ||
addTslintLoader, | ||
addTslintLoader | ||
}; |
{ | ||
"name": "customize-cra", | ||
"version": "0.2.13", | ||
"version": "0.2.14", | ||
"description": "", | ||
@@ -8,3 +8,3 @@ "repository": "arackaf/customize-cra", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "jest" | ||
}, | ||
@@ -15,3 +15,6 @@ "author": "Adam Rackis", | ||
"lodash.flow": "^3.5.0" | ||
}, | ||
"devDependencies": { | ||
"jest": "^24.8.0" | ||
} | ||
} |
@@ -65,14 +65,14 @@ # customize-cra | ||
### addBabelPresets(preset) | ||
### addBabelPreset(preset) | ||
Adds a babel plugin. Whatever you pass for `preset` will be added to Babel's `preset` array. Consult their docs for more info. | ||
Adds a babel preset. Whatever you pass for `preset` will be added to Babel's `preset` array. Consult their docs for more info. | ||
Note that this rewirer will not add the preset to the `yarn test`'s Babel configuration. See `useBabelRc()` to learn more. | ||
### addBabelPresets(presets) | ||
### addBabelPresets(...presets) | ||
A simple helper that calls `addBabelPreset` for each preset you pass in here. Make sure you use the spread operator when using this, for example | ||
A simple helper that calls `addBabelPreset` for each preset you pass in here. Make sure you don't pass an array and use the spread operator when using this, for example | ||
```js | ||
module.exports = override( | ||
...addBabelPresets([ | ||
...addBabelPresets( | ||
[ | ||
@@ -89,3 +89,3 @@ "@babel/env", | ||
"@babel/preset-react" | ||
]) | ||
) | ||
); | ||
@@ -92,0 +92,0 @@ ``` |
Sorry, the diff of this file is not supported yet
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
27844
6
615
2
1