Skip to content

Commit 9234f46

Browse files
committed
make it simpler
1 parent 7471b86 commit 9234f46

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

packages/gatsby-plugin-netlify-cms/src/gatsby-node.js

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from "path"
2-
import { get, mapValues, isPlainObject, trim, castArray } from "lodash"
2+
import { mapValues, isPlainObject, trim } from "lodash"
33
import webpack from "webpack"
44
import HtmlWebpackPlugin from "html-webpack-plugin"
55
import HtmlWebpackExcludeAssetsPlugin from "html-webpack-exclude-assets-plugin"
@@ -29,34 +29,20 @@ function deepMap(obj, fn) {
2929

3030
function replaceRule(value) {
3131
// If `value` does not have a `test` property, it isn't a rule object.
32-
if (!get(value, `test`)) {
32+
if (!value || !value.test) {
3333
return value
3434
}
3535

36-
// Return received value if no replacements are necessary.
37-
const exclude = replaceExclude(value)
38-
const loader = replaceLoader(value)
39-
if (!exclude && !loader) {
40-
return value
41-
}
42-
43-
return {
44-
...value,
45-
exclude: exclude || value.exclude,
46-
loader: loader || value.loader,
47-
}
48-
}
49-
50-
function replaceExclude(value) {
51-
// Add exclusions to Gatsby's JavaScript rule. The CMS build should always
52-
// exclude dependencies, Eg. `node_modules`.
53-
if (value.type === `javascript/auto`) {
54-
return [...castArray(value.exclude), /node_modules|bower_components/]
36+
// when javascript we exclude node_modules
37+
if (value.type === `javascript/auto` && value.exclude) {
38+
return {
39+
...value,
40+
exclude: new RegExp(
41+
[value.exclude.source, `node_modules|bower_components`].join(`|`)
42+
),
43+
}
5544
}
56-
return null
57-
}
5845

59-
function replaceLoader(value) {
6046
// Manually swap `style-loader` for `MiniCssExtractPlugin.loader`.
6147
// `style-loader` is only used in development, and doesn't allow us to pass
6248
// the `styles` entry css path to Netlify CMS.
@@ -66,7 +52,8 @@ function replaceLoader(value) {
6652
) {
6753
return MiniCssExtractPlugin.loader
6854
}
69-
return null
55+
56+
return value
7057
}
7158

7259
exports.onCreateDevServer = ({ app, store }, { publicPath = `admin` }) => {

0 commit comments

Comments
 (0)