forked from wednesday-solutions/next-bulletproof-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
babel.config.js
92 lines (86 loc) · 2.46 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const getPresets = (options = {}) => {
/**
* Styled-component prop to SSR so as to prevent className mismatch
*/
const plugins = [["styled-components", { ssr: true }], ...(options.plugins || [])];
if (process.env.NODE_ENV !== "production") {
plugins.push("babel-plugin-typescript-to-proptypes");
}
return {
presets: options.presets || ["next/babel"],
plugins,
};
};
module.exports = {
env: {
production: getPresets({
plugins: [
/**
* Remove `data-testid` from production build that is used while testing
* <div data-testid="some-component-header" /> => <div />
*/
["react-remove-properties", { properties: ["data-testid"] }],
/**
* Remove random console.log from production build, remember that
* if you need console in production use ONLY console.error or console.warn
*/
["transform-remove-console", { exclude: ["error", "warn"] }],
],
}),
development: getPresets({
presets: [
[
"next/babel",
{
"preset-react": {
/**
* Amazing plugin as it can suggest you potential fixes or things that causes
* useless rerenders, potentially saving you extra rerenders.
*/
importSource: "@welldone-software/why-did-you-render",
},
},
],
],
}),
test: getPresets({
plugins: [
/**
* Removes react propTypes in testing environment
*/
"transform-react-remove-prop-types",
/**
* Transpile import() to deferred require(), spec for reference
* @refer https://github.com/tc39/proposal-dynamic-import
*/
"transform-dynamic-import",
/**
* Rewrites all calls to require.context into calls to this global function,
* passing in __dirname as the extra parameter.
*/
"require-context-hook",
],
presets: [["next/babel"]],
}),
},
/**
* These plugins are loaded regardless of what environment you're using
*/
plugins: [
[
"babel-plugin-module-resolver",
{
root: ["."],
alias: {
"@features": "./features",
"@slices": "./store/slices",
"@store": "./store",
"@common": "./common",
"@themes": "./themes",
"@utils": "./utils",
"@containers": "./containers",
},
},
],
],
};