-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbabel.config.js
33 lines (30 loc) · 1.1 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
const path = require("path");
const fs = require("fs");
module.exports = {
presets: ["next/babel"],
plugins: [
[
"module-resolver",
{
extensions: [".js", ".jsx", ".es", ".es6", ".mjs", "ts", "tsx"],
resolvePath(sourcePath, currentFile, opts) {
if (!sourcePath.startsWith("./") && !sourcePath.startsWith("../")) {
return sourcePath;
}
if (sourcePath.endsWith(".js")) {
const relPath = path.resolve(path.dirname(currentFile), sourcePath);
const tsPath = relPath.replace(/\.js$/, ".ts");
const tsxPath = relPath.replace(/\.js$/, ".tsx");
if (fs.existsSync(tsPath)) {
return tsPath;
}
if (fs.existsSync(tsxPath)) {
return tsxPath;
}
}
return sourcePath;
},
},
],
],
};