@符号在javascript导入中做了什么? [英] What does the @ symbol do in javascript imports?

查看:85
本文介绍了@符号在javascript导入中做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

import Component from '@/components/component'

在我看的代码中,它表现得像 ../ 上升一个级别在相对于文件路径的目录中,但我想更一般地了解它的作用。遗憾的是,由于符号搜索问题,我无法在线找到任何文档。

In the code I'm looking at it behaves like ../ going up one level in the directory relative to the file path, but I'd like to know more generally what it does. Unfortunately I can't find any documentation online due to the symbol searching problem.

推荐答案

模块标识符的含义和结构取决于模块加载器模块捆绑。模块加载器不是ECMAScript规范的一部分。从JavaScript语言的角度来看,模块标识符完全不透明。所以它真的取决于你使用的是哪个模块加载器/捆绑器。

The meaning and structure of the module identifier depends on the module loader or module bundler. The module loader is not part of the ECMAScript spec. From a JavaScript language perspective, the module identifier is completely opaque. So it really depends on which module loader/bundler you are using.

你很可能有像 babel-plugin-root-import

基本上它意味着来自项目的根 ..它避免了从'../../../../components/component'导入组件等内容code>

Basically it means from the root of the project.. it avoids having to write things like import Component from '../../../../components/component'

编辑:存在的一个原因是因为从'components / component'导入组件不会这样做,而是搜索 node_modules 文件夹

One reason it exists is because import Component from 'components/component' doesn't do that but instead search in the node_modules folder

这篇关于@符号在javascript导入中做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆