|
1 | | -import { dirname } from 'path'; |
| 1 | +const nxJsBabelPreset = require('@nrwl/js/babel'); |
2 | 2 |
|
3 | | -/* |
4 | | - * Babel preset to provide TypeScript support and module/nomodule for Nx. |
5 | | - */ |
6 | | - |
7 | | -export interface NxWebBabelPresetOptions { |
8 | | - useBuiltIns?: boolean | string; |
9 | | - decorators?: { |
10 | | - decoratorsBeforeExport?: boolean; |
11 | | - legacy?: boolean; |
12 | | - }; |
13 | | - classProperties?: { |
14 | | - loose?: boolean; |
15 | | - }; |
16 | | -} |
17 | | - |
18 | | -module.exports = function (api: any, options: NxWebBabelPresetOptions = {}) { |
19 | | - api.assertVersion(7); |
20 | | - |
21 | | - const isModern = api.caller((caller) => caller?.isModern); |
22 | | - |
23 | | - // This is set by `@nrwl/web:rollup` executor |
24 | | - const isNxPackage = api.caller((caller) => caller?.isNxPackage); |
25 | | - |
26 | | - const emitDecoratorMetadata = api.caller( |
27 | | - (caller) => caller?.emitDecoratorMetadata ?? true |
| 3 | +/** @deprecated Use `@nrwl/js/babel`. */ |
| 4 | +module.exports = function (api: any, options: any = {}) { |
| 5 | + console.warn( |
| 6 | + '`@nrwl/web/babel` has been deprecated. Use `@nrwl/js/babel` instead in your .babelrc files.' |
28 | 7 | ); |
29 | | - |
30 | | - // Determine settings for `@babel/plugin-proposal-class-properties`, |
31 | | - // so that we can sync the `loose` option with `@babel/preset-env`. |
32 | | - const classProperties = options.classProperties ?? { loose: true }; |
33 | | - |
34 | | - return { |
35 | | - presets: [ |
36 | | - // Support module/nomodule pattern. |
37 | | - [ |
38 | | - require.resolve('@babel/preset-env'), |
39 | | - // For Jest tests, NODE_ENV is set as 'test' and we only want to set target as Node. |
40 | | - // All other options will fail in Jest since Node does not support some ES features |
41 | | - // such as import syntax. |
42 | | - process.env.NODE_ENV === 'test' |
43 | | - ? { targets: { node: 'current' }, loose: true } |
44 | | - : { |
45 | | - // Allow importing core-js in entrypoint and use browserlist to select polyfills. |
46 | | - useBuiltIns: options.useBuiltIns ?? 'entry', |
47 | | - corejs: 3, |
48 | | - // Do not transform modules to CJS |
49 | | - modules: false, |
50 | | - targets: isModern ? { esmodules: 'intersect' } : undefined, |
51 | | - bugfixes: true, |
52 | | - // Exclude transforms that make all code slower |
53 | | - exclude: ['transform-typeof-symbol'], |
54 | | - // This must match the setting for `@babel/plugin-proposal-class-properties` |
55 | | - loose: classProperties.loose, |
56 | | - }, |
57 | | - ], |
58 | | - [ |
59 | | - require.resolve('@babel/preset-typescript'), |
60 | | - { |
61 | | - allowDeclareFields: true, |
62 | | - }, |
63 | | - ], |
64 | | - ], |
65 | | - plugins: [ |
66 | | - !isNxPackage |
67 | | - ? [ |
68 | | - require.resolve('@babel/plugin-transform-runtime'), |
69 | | - { |
70 | | - corejs: false, |
71 | | - helpers: true, |
72 | | - regenerator: true, |
73 | | - useESModules: isModern, |
74 | | - absoluteRuntime: dirname( |
75 | | - require.resolve('@babel/runtime/package.json') |
76 | | - ), |
77 | | - }, |
78 | | - ] |
79 | | - : null, |
80 | | - require.resolve('babel-plugin-macros'), |
81 | | - emitDecoratorMetadata |
82 | | - ? require.resolve('babel-plugin-transform-typescript-metadata') |
83 | | - : undefined, |
84 | | - // Must use legacy decorators to remain compatible with TypeScript. |
85 | | - [ |
86 | | - require.resolve('@babel/plugin-proposal-decorators'), |
87 | | - options.decorators ?? { legacy: true }, |
88 | | - ], |
89 | | - [ |
90 | | - require.resolve('@babel/plugin-proposal-class-properties'), |
91 | | - classProperties, |
92 | | - ], |
93 | | - ].filter(Boolean), |
94 | | - overrides: [ |
95 | | - // Convert `const enum` to `enum`. The former cannot be supported by babel |
96 | | - // but at least we can get it to not error out. |
97 | | - { |
98 | | - test: /\.tsx?$/, |
99 | | - plugins: [ |
100 | | - [ |
101 | | - require.resolve('babel-plugin-const-enum'), |
102 | | - { |
103 | | - transform: 'removeConst', |
104 | | - }, |
105 | | - ], |
106 | | - ], |
107 | | - }, |
108 | | - ], |
109 | | - }; |
| 8 | + return nxJsBabelPreset(api, options); |
110 | 9 | }; |
0 commit comments