1
1
import path from "path"
2
- import { get , mapValues , isPlainObject , trim , castArray } from "lodash"
2
+ import { mapValues , isPlainObject , trim } from "lodash"
3
3
import webpack from "webpack"
4
4
import HtmlWebpackPlugin from "html-webpack-plugin"
5
5
import HtmlWebpackExcludeAssetsPlugin from "html-webpack-exclude-assets-plugin"
@@ -29,34 +29,20 @@ function deepMap(obj, fn) {
29
29
30
30
function replaceRule ( value ) {
31
31
// If `value` does not have a `test` property, it isn't a rule object.
32
- if ( ! get ( value , ` test` ) ) {
32
+ if ( ! value || ! value . test ) {
33
33
return value
34
34
}
35
35
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 ) , / n o d e _ m o d u l e s | b o w e r _ c o m p o n e n t s / ]
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
+ }
55
44
}
56
- return null
57
- }
58
45
59
- function replaceLoader ( value ) {
60
46
// Manually swap `style-loader` for `MiniCssExtractPlugin.loader`.
61
47
// `style-loader` is only used in development, and doesn't allow us to pass
62
48
// the `styles` entry css path to Netlify CMS.
@@ -66,7 +52,8 @@ function replaceLoader(value) {
66
52
) {
67
53
return MiniCssExtractPlugin . loader
68
54
}
69
- return null
55
+
56
+ return value
70
57
}
71
58
72
59
exports . onCreateDevServer = ( { app, store } , { publicPath = `admin` } ) => {
0 commit comments