forked from kriasoft/graphql-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
babel.config.cjs
76 lines (69 loc) · 1.73 KB
/
babel.config.cjs
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
72
73
74
75
76
/* SPDX-FileCopyrightText: 2016-present Kriasoft <[email protected]> */
/* SPDX-License-Identifier: MIT */
/**
* Babel configuration
*
* @see https://babeljs.io/docs/en/options
* @param {import("@babel/core").ConfigAPI} api
* @returns {import("@babel/core").TransformOptions}
*/
module.exports = function config(api) {
const isNodeEnv = api.caller((caller) =>
[
"babel-jest",
"@babel/register",
"@babel/cli",
"@babel/node",
"@rollup/plugin-babel",
].includes(caller?.name || ""),
);
return {
presets: [
[
"@babel/preset-env",
isNodeEnv ? { targets: { node: "16", esmodules: false } } : {},
],
],
plugins: [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread",
"babel-plugin-relay",
[
"babel-plugin-import",
{
libraryName: "lodash",
libraryDirectory: "",
camel2DashComponentName: false,
},
"lodash",
],
],
ignore: api.env() === "test" ? [] : ["**/__tests__/**", "**/*.test.ts"],
sourceMaps: api.env() === "production",
overrides: [
{
test: /\.tsx?$/,
presets: ["@babel/preset-typescript"],
},
{
test: /\.tsx$/,
presets: [
[
"@babel/preset-react",
{
development: api.env() === "development",
useBuiltIns: true,
runtime: "automatic",
importSource: "@emotion/react",
},
],
],
plugins: ["@emotion/babel-plugin"],
},
{
test: "**/*.d.ts",
presets: [["@babel/preset-env", { targets: { esmodules: true } }]],
},
],
};
};