-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgatsby-node.js
52 lines (44 loc) · 1.16 KB
/
gatsby-node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const webpack = require("webpack")
const CSS_PATTERN = /\.css$/
const MODULE_CSS_PATTERN = /\.module\.css$/
const isCssRules = rule =>
rule.test &&
(rule.test.toString() === CSS_PATTERN.toString() ||
rule.test.toString() === MODULE_CSS_PATTERN.toString())
const findCssRules = config =>
config.module.rules.find(
rule => Array.isArray(rule.oneOf) && rule.oneOf.every(isCssRules)
)
exports.onCreateWebpackConfig = ({
getConfig,
stage,
rules,
loaders,
plugins,
actions,
}) => {
if (process.env.NODE_ENV !== "development") {
return
}
const config = getConfig()
const cssRules = findCssRules(config)
if (cssRules) {
cssRules.oneOf.forEach(statement => {
statement.use = statement.use.map(item => {
if (
item.loader.match(/\/css-loader\//) &&
item.options.modules === true
) {
item.loader = "typings-for-css-modules-loader"
item.options = {
...item.options,
namedExport: true,
}
}
return item
})
})
}
config.plugins.push(new webpack.WatchIgnorePlugin([/css\.d\.ts$/]))
actions.replaceWebpackConfig(config)
}