ES6 import 等同于 require() 没有 exports

ES6 import equivalent of require() without exports

通过使用 require(./filename),我可以在 filename 中包含并执行代码,而无需在 filename 本身中定义任何导出。

ES6 中使用 import 的等价物是什么?

谢谢

等价于:

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