-
Notifications
You must be signed in to change notification settings - Fork 268
/
babel.js
71 lines (59 loc) · 1.79 KB
/
babel.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
import { getBabelLoader } from "../utilities";
export const addBabelPlugin = plugin => config => {
getBabelLoader(config).options.plugins.push(plugin);
return config;
};
export const addExternalBabelPlugin = plugin => config => {
const outsideBabelOptions = getBabelLoader(config, true).options;
if (!outsideBabelOptions.plugins) {
outsideBabelOptions.plugins = [];
}
outsideBabelOptions.plugins.push(plugin);
return config;
};
export const addBabelPreset = preset => config => {
getBabelLoader(config).options.presets.push(preset);
return config;
};
export const addDecoratorsLegacy = () => config =>
addBabelPlugin(["@babel/plugin-proposal-decorators", { legacy: true }])(
config
);
export const useBabelRc = () => config => {
getBabelLoader(config).options.babelrc = true;
return config;
};
export const babelInclude = include => config => {
getBabelLoader(config).include = include;
return config;
};
/**
* Replaces the `exclude` option of `babel-loader`.
* @param exclude The new `exclude` value.
*/
export const babelExclude = exclude => config => {
getBabelLoader(config).exclude = exclude;
return config;
};
export const addBabelPlugins = (...plugins) =>
plugins.map(p => addBabelPlugin(p));
export const addExternalBabelPlugins = (...plugins) =>
plugins.map(p => addExternalBabelPlugin(p));
export const addBabelPresets = (...plugins) =>
plugins.map(p => addBabelPreset(p));
export const fixBabelImports = (libraryName, options) =>
addBabelPlugin([
"import",
Object.assign(
{},
{
libraryName
},
options
),
`fix-${libraryName}-imports`
]);
export const removeInternalBabelPlugin = pluginName => config => {
config.plugins = config.plugins.filter(p => p.constructor.name !== pluginName);
return config;
};