-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathbabel.config.cjs
More file actions
71 lines (67 loc) · 1.73 KB
/
babel.config.cjs
File metadata and controls
71 lines (67 loc) · 1.73 KB
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
// Node.js environment with default
// https://nodejs.org/en/learn/getting-started/nodejs-the-difference-between-development-and-production
const { NODE_ENV = 'development' } = process.env;
/**
* Babel config
*
* @type {TransformOptions}
*/
module.exports = {
browserslistEnv: 'javascripts',
presets: [
[
'@babel/preset-env',
{
// Apply bug fixes to avoid transforms
bugfixes: true,
// Apply smaller "loose" transforms for browsers
loose: true,
// Apply ES module transforms for Jest
// https://jestjs.io/docs/ecmascript-modules
modules: NODE_ENV === 'test' ? 'auto' : false,
},
],
[
'@babel/preset-react',
{
development: NODE_ENV === 'test' || NODE_ENV === 'development',
runtime: 'automatic',
useBuiltIns: true,
},
],
'@babel/preset-typescript',
],
env: {
test: {
browserslistEnv: 'node',
plugins: [
// Override package.json "imports" for Jest to use sources
// otherwise a build step to output `./dist` is necessary
[
'module-resolver',
{
alias: {
'#components': './src/components',
'#patterns': './src/patterns',
'#util': './src/util',
'nhsuk-react-components': './src/index.ts',
},
},
],
// Remove mandatory ES module file extensions for Jest
// https://nodejs.org/api/esm.html#mandatory-file-extensions
[
'replace-import-extension',
{
extMapping: {
'.js': '',
},
},
],
],
},
},
};
/**
* @import { TransformOptions } from '@babel/core'
*/