-
Notifications
You must be signed in to change notification settings - Fork 317
/
babel.config.js
57 lines (51 loc) · 1.75 KB
/
babel.config.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
const createResolvePath = require('babel-plugin-tsconfig-paths-module-resolver').createResolvePath;
const defaultResolvePath = createResolvePath();
function customResolvePath(sourceFile, currentFile, opts) {
// Do not transform @okta/handlebars-inline-precompile
if (sourceFile === '@okta/handlebars-inline-precompile') {
return sourceFile;
}
return defaultResolvePath(sourceFile, currentFile, opts);
}
const presets = [
'@babel/preset-typescript', // must run before preset-env: https://github.com/babel/babel/issues/12066
];
const COURAGE_DIST = './packages/@okta/courage-dist/esm';
const plugins = [
'./packages/@okta/babel-plugin-handlebars-inline-precompile', // should always come first
// tsconfig.paths replaces babel/webpack aliases
['tsconfig-paths-module-resolver', {
resolvePath: customResolvePath,
alias: {
'^handlebars(/runtime)?$': `${COURAGE_DIST}/lib/handlebars/dist/cjs/handlebars.runtime.js`,
'^backbone$': `${COURAGE_DIST}/src/courage/vendor/backbone.js`,
'^underscore$': `${COURAGE_DIST}/lib/underscore/underscore-min.js`
}
}],
['transform-amd-to-commonjs', {
restrictToTopLevelDefine: false
}],
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-nullish-coalescing-operator', // double question mark
'@babel/plugin-transform-shorthand-properties' // ES shorthand functions cannot be used as constructors
];
const assumptions = {
setPublicClassFields: true
};
// Used by babel-jest
if (process.env.NODE_ENV === 'test') {
presets.unshift(
['@babel/preset-env', {
exclude: [
'@babel/plugin-transform-regenerator'
]
}]
);
}
module.exports = {
presets,
plugins,
assumptions,
sourceMaps: true
};