缩短ES2015导入路径 [英] Shorten ES2015 import paths
本文介绍了缩短ES2015导入路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在处理一个大型的ES2015项目,该项目有很多引用语句参考深层目录结构中的一个库。目前,进口采取的形式是
I am working on a large ES2015 project that has a lot of import statements referring to a library in a deep directory structure. Currently, imports take the form of
import Status from '../../../Scripts/core/components/Status';
//import ...
是否有任何解决方法来缩短导入路径的长度除了更改源文件的位置?
Are there any workarounds to shorten the length of import paths other than changing the location of the source files?
编辑:我正在使用带有webpack的babel-loader来编译模块。
edit: I am using babel-loader with webpack to compile the modules.
推荐答案
您还可以使用 resolve.alias
来处理可能移动的根源:
You can also use resolve.alias
to handle roots that might move around:
resolve: {
alias: {
importName: 'actual/path/here',
'__another_alias__': 'another/path'
}
}
然后您可以使用它作为:
Which you could then use as:
import someImport from 'importName';
import anotherImport from '__another_alias__/sub/path';
这篇关于缩短ES2015导入路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文