简体   繁体   English

如何在 NodeJS 项目中自动“审核”或“合理化”我的导入?

[英]How can I automatically 'audit' or 'rationalise' my imports in a NodeJS project?

I'd like to be able to go through my project and automatically change all instances in which an entire library is imported when only one export of that library is needed to only import the export(s) needed.我希望能够通过我的项目 go 并自动更改导入整个库的所有实例,当只需要该库的一个导出以仅导入所需的导出时。 Thus因此

import R from 'ramda'

const sillyValue = R.add(2,3)

const moreSilly = R.always('foo')

would be changed to将更改为

import {add, always} from 'ramda'

const sillyValue = add(2,3)

const moreSilly = always('foo')

Is there any sort of utility that I can run to do this automatically for all the modules in my project at once?是否有任何类型的实用程序可以让我立即为项目中的所有模块自动执行此操作? I have WebStorm, but so far I haven't found any way to do it using the IDE ('Optimize Imports', while nice, doesn't seem to do what I want).我有 WebStorm,但到目前为止,我还没有找到任何使用 IDE 的方法(“优化导入”,虽然很好,但似乎没有做我想要的)。

WebStorm doesn't have such inspection; WebStorm 没有这样的检查; you can try using ESLint for this, see eslint-plugin-import plugin, no-named-as-default-member rule您可以尝试为此使用 ESLint,请参阅eslint-plugin-import plugin, no-named-as-default-member rule

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

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