-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-node.js
77 lines (72 loc) · 2.1 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const { siteMetadata } = require('./gatsby-config');
const replacePath = (path) => (path === `/` ? path : path.replace(/\/$/, ``));
const isProd = process.env.NODE_ENV === `production`;
exports.onCreatePage = ({ page, actions }) => {
// Remove pages protected by featureFlag
if (isProd && !siteMetadata.featureFlags.open) {
if (
['/application', '/dashboard', '/activate', '/forgot', '/reset_password', '/register', '/login'].includes(
replacePath(page.path),
)
) {
actions.deletePage(page);
}
}
if (isProd && !siteMetadata.featureFlags.schedule) {
if (['/schedule'].includes(replacePath(page.path))) {
actions.deletePage(page);
}
}
if (isProd && !siteMetadata.featureFlags.discord) {
if (['/discord'].includes(replacePath(page.path))) {
actions.deletePage(page);
}
}
};
exports.onCreateWebpackConfig = ({ actions, stage, loaders, getConfig }) => {
const isSSR = [`develop-html`, `build-html`].includes(stage);
const config = getConfig();
config.module.rules = [
...config.module.rules.filter(
(rule) => String(rule.test) !== String(/\.jsx?$/),
),
{
...loaders.js(),
test: /\.(js|jsx)?$/,
exclude: (modulePath) =>
/node_modules/.test(modulePath) &&
!/@htv(\/|\\)(ui-kit)/.test(modulePath),
},
{
oneOf: [
{
test: /\.module\.scss$/,
use: [
!isSSR && loaders.miniCssExtract({ modules: true }),
loaders.css({
importLoaders: 2,
modules: {
localIdentName: isProd
? `[hash:base64:8]`
: `[name]__[local]--[hash:base64:8]`,
},
}),
loaders.postcss(),
require.resolve(`sass-loader`),
].filter(Boolean),
},
{
test: /\.deferred\.scss$/,
use: [
loaders.file({
name: `static/[hash:base64:8].css`,
}),
loaders.postcss(),
`sass-loader`,
],
},
],
},
];
actions.replaceWebpackConfig();
};