forked from athensresearch/athens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
babel.config.js
80 lines (74 loc) · 3.12 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
const {existsSync, lstatSync} = require("fs");
const {resolve, dirname} = require("path");
function isRelativeImport(path){
return path.startsWith(".");
}
function isDirectory(path) {
return existsSync(path) && lstatSync(path).isDirectory();
}
function resolveImport (from, to) {
return resolve(dirname(from), to);
}
function replaceDirectoryImports() {
return {
visitor: {
ImportDeclaration: (path, state) => {
const importPath = path.node.source.value;
const fileName = state.file.opts.filename;
if (isRelativeImport(importPath) && isDirectory(resolveImport(fileName, importPath))) {
path.node.source.value += "/index";
}
}
}
}
}
// This config will output files to ./src/gen/components via the `yarn components` script
// See https://shadow-cljs.github.io/docs/UsersGuide.html#_javascript_dialects
module.exports = {
presets: [
"@babel/env",
// Compile tsx files.
"@babel/preset-typescript",
// Use the react runtime import if available.
["@babel/preset-react", {"runtime": "automatic"}]
],
plugins: [
// Add /index to all relative directory imports, because Shadow-CLJS does not support
// them (https://github.com/thheller/shadow-cljs/issues/841#issuecomment-777323477)
// NB: Putting these files in node_modules would have fixed the directory imports
// but broken hot reload (https://github.com/thheller/shadow-cljs/issues/764#issuecomment-663064549)
replaceDirectoryImports,
// Allow using @/ for root relative imports in the component library.
["module-resolver", {alias: {"@": "./src/js/components"}}],
// Transform material-ui imports into deep imports for faster reload.
// material-ui is very big, and importing it all can slow down development rebuilds by a lot.
// https://material-ui.com/guides/minimizing-bundle-size/#development-environment
["transform-imports", {
"@material-ui/core": {
transform: "@material-ui/core/esm/${member}",
preventFullImport: true
},
"@material-ui/icons": {
transform: "@material-ui/icons/esm/${member}",
preventFullImport: true
}
}],
// Our build doesn't need the {loose: true} option, but if not included it wil
// show a lot of warnings on the storybook build.
["@babel/proposal-class-properties", {loose: true}],
["@babel/proposal-object-rest-spread", {loose: true}],
// Used only by storybook, but must be included to avoid build warnings/errors.
["@babel/plugin-proposal-private-methods", {loose: true}],
["@babel/plugin-proposal-private-property-in-object", {loose: true}],
// Import helpers from @babel/runtime instead of duplicating them everywhere.
"@babel/plugin-transform-runtime",
// Better debug information for styled components.
// https://styled-components.com/docs/tooling#babel-plugin
"babel-plugin-styled-components"
],
// Do not apply this babel config to node_modules.
// Shadow-CLJS also runs babel over node_modules and we don't want this
// configuration to apply to it.
// We still want it to be picked up by storybook though.
exclude: ["node_modules"]
}