Skip to content

Commit 8466bfc

Browse files
committed
chore: Setup absloute import
1 parent fcadb8f commit 8466bfc

File tree

6 files changed

+69
-22
lines changed

6 files changed

+69
-22
lines changed

.babelrc

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"presets": [["next/babel"]],
3+
"plugins": [
4+
[
5+
"module-resolver",
6+
{
7+
"root": ["./src"],
8+
"alias": {
9+
"@components": "./src/components"
10+
}
11+
}
12+
]
13+
]
14+
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@types/node": "^13.9.2",
1818
"@types/react": "^16.9.23",
1919
"@types/react-dom": "^16.9.5",
20+
"babel-plugin-module-resolver": "^4.0.0",
2021
"typescript": "^3.8.3"
2122
}
2223
}

src/components/Title.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from "react";
2+
3+
const Title: React.FC<{}> = () => (
4+
<h1 className="title">
5+
Welcome to <a href="https://nextjs.org">Next.js!</a>
6+
</h1>
7+
);
8+
9+
export default Title;

src/pages/index.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import Head from 'next/head'
1+
import Head from "next/head";
2+
3+
import Title from "@components/Title";
24

35
const Home = () => (
46
<div className="container">
@@ -8,9 +10,7 @@ const Home = () => (
810
</Head>
911

1012
<main>
11-
<h1 className="title">
12-
Welcome to <a href="https://nextjs.org">Next.js!</a>
13-
</h1>
13+
<Title />
1414

1515
<p className="description">
1616
Get started by editing <code>pages/index.js</code>
@@ -198,6 +198,6 @@ const Home = () => (
198198
}
199199
`}</style>
200200
</div>
201-
)
201+
);
202202

203-
export default Home
203+
export default Home;

tsconfig.json

+8-14
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "es5",
4-
"lib": [
5-
"dom",
6-
"dom.iterable",
7-
"esnext"
8-
],
4+
"lib": ["dom", "dom.iterable", "esnext"],
95
"allowJs": true,
106
"skipLibCheck": true,
117
"strict": false,
@@ -16,14 +12,12 @@
1612
"moduleResolution": "node",
1713
"resolveJsonModule": true,
1814
"isolatedModules": true,
19-
"jsx": "preserve"
15+
"jsx": "preserve",
16+
"baseUrl": "./src",
17+
"paths": {
18+
"@components/*": ["./components/*"]
19+
}
2020
},
21-
"exclude": [
22-
"node_modules"
23-
],
24-
"include": [
25-
"next-env.d.ts",
26-
"**/*.ts",
27-
"**/*.tsx"
28-
]
21+
"exclude": ["node_modules"],
22+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
2923
}

yarn.lock

+31-2
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,17 @@ babel-plugin-dynamic-import-node@^2.3.0:
13741374
dependencies:
13751375
object.assign "^4.1.0"
13761376

1377+
babel-plugin-module-resolver@^4.0.0:
1378+
version "4.0.0"
1379+
resolved "https://registry.yarnpkg.com/babel-plugin-module-resolver/-/babel-plugin-module-resolver-4.0.0.tgz#8f3a3d9d48287dc1d3b0d5595113adabd36a847f"
1380+
integrity sha512-3pdEq3PXALilSJ6dnC4wMWr0AZixHRM4utpdpBR9g5QG7B7JwWyukQv7a9hVxkbGFl+nQbrHDqqQOIBtTXTP/Q==
1381+
dependencies:
1382+
find-babel-config "^1.2.0"
1383+
glob "^7.1.6"
1384+
pkg-up "^3.1.0"
1385+
reselect "^4.0.0"
1386+
resolve "^1.13.1"
1387+
13771388
13781389
version "6.18.0"
13791390
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz#0af32a9a6e13ca7a3fd5069e62d7b0f58d0d8946"
@@ -2568,6 +2579,14 @@ [email protected]:
25682579
resolved "https://registry.yarnpkg.com/finally-polyfill/-/finally-polyfill-0.1.0.tgz#2a17b16581d9477db16a703c7b79a898ac0b7d50"
25692580
integrity sha512-J1LEcZ5VXe1l3sEO+S//WqL5wcJ/ep7QeKJA6HhNZrcEEFj0eyC8IW3DEZhxySI2bx3r85dwAXz+vYPGuHx5UA==
25702581

2582+
find-babel-config@^1.2.0:
2583+
version "1.2.0"
2584+
resolved "https://registry.yarnpkg.com/find-babel-config/-/find-babel-config-1.2.0.tgz#a9b7b317eb5b9860cda9d54740a8c8337a2283a2"
2585+
integrity sha512-jB2CHJeqy6a820ssiqwrKMeyC6nNdmrcgkKWJWmpoxpE8RKciYJXCcXRq1h2AzCo5I5BJeN2tkGEO3hLTuePRA==
2586+
dependencies:
2587+
json5 "^0.5.1"
2588+
path-exists "^3.0.0"
2589+
25712590
find-cache-dir@^1.0.0:
25722591
version "1.0.0"
25732592
resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-1.0.0.tgz#9288e3e9e3cc3748717d39eade17cf71fc30ee6f"
@@ -2741,7 +2760,7 @@ glob-to-regexp@^0.4.1:
27412760
resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz#c75297087c851b9a578bd217dd59a92f59fe546e"
27422761
integrity sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==
27432762

2744-
glob@^7.0.3, glob@^7.1.3, glob@^7.1.4:
2763+
glob@^7.0.3, glob@^7.1.3, glob@^7.1.4, glob@^7.1.6:
27452764
version "7.1.6"
27462765
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6"
27472766
integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==
@@ -3273,6 +3292,11 @@ [email protected]:
32733292
dependencies:
32743293
minimist "^1.2.0"
32753294

3295+
json5@^0.5.1:
3296+
version "0.5.1"
3297+
resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821"
3298+
integrity sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE=
3299+
32763300
json5@^1.0.1:
32773301
version "1.0.1"
32783302
resolved "https://registry.yarnpkg.com/json5/-/json5-1.0.1.tgz#779fb0018604fa854eacbf6252180d83543e3dbe"
@@ -4968,6 +4992,11 @@ requires-port@^1.0.0:
49684992
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
49694993
integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=
49704994

4995+
reselect@^4.0.0:
4996+
version "4.0.0"
4997+
resolved "https://registry.yarnpkg.com/reselect/-/reselect-4.0.0.tgz#f2529830e5d3d0e021408b246a206ef4ea4437f7"
4998+
integrity sha512-qUgANli03jjAyGlnbYVAV5vvnOmJnODyABz51RdBN7M4WaVu8mecZWgyQNkG8Yqe3KRGRt0l4K4B3XVEULC4CA==
4999+
49715000
resolve-from@^3.0.0:
49725001
version "3.0.0"
49735002
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-3.0.0.tgz#b22c7af7d9d6881bc8b6e653335eebcb0a188748"
@@ -4994,7 +5023,7 @@ resolve-url@^0.2.1:
49945023
resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a"
49955024
integrity sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=
49965025

4997-
resolve@^1.10.0, resolve@^1.3.2, resolve@^1.8.1:
5026+
resolve@^1.10.0, resolve@^1.13.1, resolve@^1.3.2, resolve@^1.8.1:
49985027
version "1.15.1"
49995028
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.15.1.tgz#27bdcdeffeaf2d6244b95bb0f9f4b4653451f3e8"
50005029
integrity sha512-84oo6ZTtoTUpjgNEr5SJyzQhzL72gaRodsSfyxC/AXRvwu0Yse9H8eF9IpGo7b8YetZhlI6v7ZQ6bKBFV/6S7w==

0 commit comments

Comments
 (0)