-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinaria.js
28 lines (27 loc) · 800 Bytes
/
linaria.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
const __PROD__ = process.env.NODE_ENV === 'production';
const matches = ({test}) => test instanceof RegExp && test.source.includes('ts');
const babel = ({presets}) => ({
// [["node_modules/babel-preset-react-app/index.js",{"runtime":"automatic"}]]
presets: presets.map(([preset, options]) => [preset, {
...options,
useESModules: false,
}]),
});
const pipeline = ({loader, options}) => [
{loader, options},
{
loader: '@linaria/webpack5-loader',
options: {
babelOptions: babel(options),
sourceMap: !__PROD__,
cacheDirectory: false,
}
},
];
export function inject(rule) {
if (!matches(rule)) return;
rule.use = pipeline(rule);
delete rule.loader;
delete rule.options;
return true;
}