如何避免使用无限制进口的相对进口
我想要的是
我要避免使用../../../
的深度相对导入,我只想允许相对导入package.json
file ,因此我设置了Eslint 无限制的Imports
这样的规则:
.eslintrc.js
module.exports = {
rules: {
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['**/../../*', '!**/../../package.json'],
message: 'Please use alias instead of deep relative imports.',
},
],
},
],
},
};
此配置的问题
是,它正在从package.json 也是如此,这是丢弃错误:
导入 *作为packagejson从'../../../../ pockage.json';
我如何避免除>
以外的所有相对导入package.json
一个?
What I want
I want to avoid the deep relative imports like ../../../
, and I want to allow only the relative import of package.json
file, so I set up the eslint no-restricted-imports
rule like so:
.eslintrc.js
module.exports = {
rules: {
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['**/../../*', '!**/../../package.json'],
message: 'Please use alias instead of deep relative imports.',
},
],
},
],
},
};
The problem
The problem with this configuration is that it is taking the imports from package.json
as well, so this is throwing error: import * as PackageJSON from '../../../package.json';
how can I avoid all relative imports except the package.json
one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论