-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (49 loc) · 1.16 KB
/
index.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
module.exports = {
overrideCracoConfig({ cracoConfig, pluginOptions }) {
const {
sass = true,
} = pluginOptions;
if (!cracoConfig.babel) {
cracoConfig.babel = {};
}
if (!cracoConfig.babel.plugins) {
cracoConfig.babel.plugins = [];
}
cracoConfig.babel.plugins.push(
[
'styled-jsx/babel',
sass && { 'plugins': ['styled-jsx-plugin-sass'] },
].filter(Boolean),
);
return cracoConfig;
},
overrideWebpackConfig: ({ webpackConfig, pluginOptions, context: { env } }) => {
const {
cssFileSupport = true,
cssFileTest = /\.styled\.(s)css$/,
} = pluginOptions;
if (!cssFileSupport) {
return webpackConfig;
}
const oneOfRule = webpackConfig.module.rules.find(rule => rule.oneOf);
if (!oneOfRule) {
return console.log(
`Can't find a 'oneOf' rule under module.rules in the ${env} webpack config!`,
'webpack+rules+oneOf',
);
}
// Insert this rule right before the last rule
oneOfRule.oneOf.splice(oneOfRule.oneOf.length - 1, 0, {
test: cssFileTest,
use: [
{
loader: require('styled-jsx/webpack').loader,
options: {
type: 'scoped',
},
},
],
});
return webpackConfig;
},
};