0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[React] importを絶対パスで記述

Posted at

Reactでコンポーネントをimportする際に、
離れた階層のコンポーネントを相対パスで読み込む場合、

import {testComponent} from "...../Components/testComponent";

などど記述しなくてはいけなくなり可読性がかなり落ちます。
絶対パスでの設定方法は、プロジェクトのルートの
jsの場合=jsconfig.json
tsの場合=tsconfig.jsonを作成して以下を記述します。

{
    "compilerOptions": {
        "paths": {
            "@/*": ["resources/js/*"]
        },
    },
}

を記述することで、
resources/js/直下のディレクトリを、@で指定できるので、

import {testComponent} from "@/Components/testComponent";

と記述することができます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?