简体   繁体   English

`import from '@/some/path'` 中的 @ 是什么意思

[英]What does the @ mean in `import from '@/some/path'`

Using IntelliJ IDEA to write a webapp in TypeScript, it autocomplete imports from other files of my project like this:使用 IntelliJ IDEA 在 TypeScript 中编写了一个 webapp,它自动完成从我项目的其他文件中导入,如下所示:

import {Symbol} from '@/components/Symbol';

What is the meaning of the @ here?这里的@是什么意思? Where is it documented?它在哪里记录?

Note that this is when importing files from the same project.请注意,这是从同一项目导入文件时的情况。 Imports from npm packages only use the package name (which may start with a @).从 npm 包导入仅使用 package 名称(可能以 @ 开头)。

I haven't found anything about this in TypeScript Module Resolution , and when searching for typescript @ import in Google or SO, it seems the @ character from the query is ignored...我没有在TypeScript Module Resolution中找到任何关于此的信息,并且在 Google 或 SO 中搜索typescript @ import时,似乎查询中的@字符被忽略了......

Edit: This is in a Next.js project created with npx create-next-app .编辑:这是在使用 npx npx create-next-app的 Next.js 项目中。

If you are using vite or webpack, then your configuration will have a resolve.alias key to alias strings to a path.如果你使用 vite 或 webpack,那么你的配置将有一个resolve.alias键来为路径别名字符串。 Vite documentation Webpack documentation vite文档Webpack 文档

This turned out to be a tsconfig path , which was put there by npx create-next-app :这原来是一个tsconfig 路径,由 npx npx create-next-app放在那里:

{
  "compilerOptions": {
    "paths": {
      "@/*": ["./src/*"]
    }
  },
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM