使用require(./filename)
我可以在 filename 中包含并执行代码,而不在 filename 本身内定义任何导出。
使用import
的ES6中的等效内容是什么?
由于
答案 0 :(得分:52)
等价物只是:
import "./filename";
以下是一些可能的语法变体:
import defaultMember from "module-name";
import * as name from "module-name";
import { member } from "module-name";
import { member as alias } from "module-name";
import { member1 , member2 } from "module-name";
import { member1 , member2 as alias2 , [...] } from "module-name";
import defaultMember, { member [ , [...] ] } from "module-name";
import defaultMember, * as name from "module-name";
import "module-name";
消息来源: MDN