-
Notifications
You must be signed in to change notification settings - Fork 52
/
node.api.js
82 lines (75 loc) · 2.33 KB
/
node.api.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
78
79
80
81
82
import ExtractCssChunks from 'extract-css-chunks-webpack-plugin';
import autoprefixer from 'autoprefixer';
import postcssFlexbugsFixes from 'postcss-flexbugs-fixes';
// Add support for CSS Modules with Sass
// CSS modules must use the file extension ".module.scss" or ".module.sass".
export default () => ({
webpack: (config, {stage}) => {
config.module.rules[0].oneOf.unshift({
test: /\.s(a|c)ss$/,
use: initLoaders({stage, modules: false}),
});
// CSS modules rule must come first in the array
config.module.rules[0].oneOf.unshift({
test: /\.module.s(a|c)ss$/,
use: initLoaders({stage, modules: true}),
});
if (
config.optimization.splitChunks &&
config.optimization.splitChunks.cacheGroups.styles
) {
config.optimization.splitChunks.cacheGroups.styles.test = /\.(c|sc|sa)ss$/;
}
return config;
},
});
function initLoaders({stage, modules = false}) {
const cssLoader = {
loader: 'css-loader',
options: {
modules: modules,
localIdentName: '[name]__[local]--[hash:base64:5]',
exportOnlyLocals: stage === 'node',
importLoaders: 1,
sourceMap: false,
},
};
const sassLoader = {
loader: require.resolve('sass-loader'),
options: {
sassOptions: {includePaths: ['src']},
},
};
const postCssLoader = {
loader: 'postcss-loader',
options: {
sourceMap: true,
ident: 'postcss',
plugins: () => [
postcssFlexbugsFixes,
autoprefixer({flexbox: 'no-2009'}),
],
},
};
switch (stage) {
case 'development':
case 'dev':
return [
{loader: ExtractCssChunks.loader, options: {hot: true}},
cssLoader,
postCssLoader,
sassLoader,
];
case 'node':
// Don't extract css to file during node build process
return [cssLoader, postCssLoader, sassLoader];
default:
// Prod
return [
ExtractCssChunks.loader,
cssLoader,
postCssLoader,
sassLoader,
];
}
}