本文介绍了如何在连字符中使用ES6导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的不知道该怎么做,也不知道如何用谷歌搜索.

I really don't know how to do this and not sure how to google either.

现在我有这个

let source = require('vinyl-source-stream');

我想更改为导入方式,但这不起作用

I would like to change to be import but this doesn't work

import {'vinyl-source-stream' as source} from 'vinyl-source-stream';

推荐答案

如果该模块甚至支持ES6导入/导出系统,那么您想要的是:

If that module even supports the ES6 import/export system, then what you want is this:

import source from 'vinyl-source-stream';

您的版本正在尝试从模块中导入名为 vinyl-source-stream 的导出值;相反,您只希望将模块本身导入(在这种情况下,导入到名为 source 的对象中).

Your version is attempting to import an exported value named vinyl-source-stream from the module; instead, you just want the module itself to be imported (into an object named source in this case).

如果您要导入模块中的所有内容,而不仅仅是默认导出,请使用以下代码:

If you want everything in the module imported, instead of just the default exports, use this instead:

import * as source from 'vinyl-source-stream';

但是,如果未实际编写模块以使用新系统,则上述两种方法均无效.

But neither of those will work if the module isn't actually written to use the new system.

这篇关于如何在连字符中使用ES6导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 06:15
查看更多