node6中的ES6变量导入名称? [英] ES6 variable import name in node.js?

查看:89
本文介绍了node6中的ES6变量导入名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在使用ES6导入时将某些东西导入到提供变量名称的模块中?



我想根据配置中提供的值在运行时导入一些模块:

 从'./utils/'导入一些内容+ variableName; 


解决方案

不与 import 语句。 import export 的定义方式是静态分析,所以它们不能依赖于运行时信息。 / p>

您正在寻找加载程序API(polyfill ),但是我对于规范的状态有点不清楚:

  System.import('。 / utils /'+ variableName).then(function(m){
console.log(m);
});


is it possible to import something into module providing variable name while using ES6 import?

I.e. I want to import some module at a runtime depending on values provided in a config:

import something from './utils/' + variableName;

解决方案

Not with the import statement. import and export are defined in such a way that they are statically analyzable, so they cannot depend on runtime information.

You are looking for the loader API (polyfill), but I'm a bit unclear about the status of the specification:

System.import('./utils/' + variableName).then(function(m) {
  console.log(m);
});

这篇关于node6中的ES6变量导入名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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