关于模块导入导出的问题
Last updated
Was this helpful?
Last updated
Was this helpful?
#
使用 webpack
打包出来的结果和书中不一致。
环境
问题
模块使用 module.exports = xx
导出,在另一个模块导入的时候,下面两种导入的结果是一致的
阮老师的代码中是这么写的
而下面的结果和书中类似
上面的结果说明,webpack
处理的时候,
module.exports
导出的,import x from 'mod'
和 import * as x from 'mod'
相同
export default
导出的,import x from 'mod'
和 import * as x from 'mod'
不同,后者是整个模块的内容
阮老师警告:这部分过时了,Node.js
已经明确了,commonjs
和 es6
模块不得混用。也就是说,不能用 import
命令去加载 commonjs
模块。