forked from eps1lon/dom-accessibility-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.babelrc.js
60 lines (58 loc) · 1.53 KB
/
.babelrc.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
module.exports = {
presets: [
[
require.resolve("@babel/preset-env"),
// for jest we need to transpile esmodules
// otherwise transform-commonjs takes care of the correct module syntax
{ modules: process.env.NODE_ENV === "test" ? "auto" : false },
],
require.resolve("@babel/preset-typescript"),
],
plugins: [require.resolve("@babel/plugin-proposal-class-properties")],
env: {
cjs: {
plugins: [
[
require.resolve("@babel/plugin-transform-modules-commonjs"),
// helps rollup identify exports but also means __esmodule is enumerated
// not aware of a use case for enumerating imports though
{ loose: true },
],
],
},
esm: {
plugins: [
function rewriteRelativeImportsToMjs() {
const extension = "mjs";
/**
*
* @param {ImportDeclaration | ExportNamedDeclaration} declaration
*/
function rewriteRelativeImports(declaration) {
if (declaration.source === null) {
return;
}
const specifier = declaration.source.value;
const isRelativeSpecifier = specifier.startsWith(".");
if (isRelativeSpecifier) {
declaration.source.value = `${specifier}.${extension}`;
}
}
return {
visitor: {
ExportAllDeclaration(path, state) {
rewriteRelativeImports(path.node);
},
ExportNamedDeclaration(path, state) {
rewriteRelativeImports(path.node);
},
ImportDeclaration(path, state) {
rewriteRelativeImports(path.node);
},
},
};
},
],
},
},
};