来来来代码先上
js/主要。js
import *, as aliasPerson 得到“。/person.js"; import defaultPerson 得到“。/person.js"; console.log (“alias  person is  below …“); console.log (aliasPerson); console.log (aliasPerson.prototype); console.log (“default  person is  below …“); console.log (defaultPerson); console.log (defaultPerson.prototype);
js/人。js
webpack.config。js
var entryFilePath =,“。/js/main.js"; var webpackConfig =, { ,,,条目:entryFilePath, ,,,输出:{ ,,,,,文件名:,“result.js" ,,}, ,,,模块:{ ,,,,,//,规则:,[{测试:/\ . js/美元,装载机:,& # 39;babel-loader& # 39;}), ,,} }; 时间=module.exports webpackConfig;
。以前babelrc
{ “presets"才能:, ,,,,,“es2015", ,,,,,“stage-3" ,,,, ,,,“plugins":, ,,,,,(“transform-runtime", ,,,,,,,{ ,,,,,,,,,“helpers":,假的, ,,,,,,,,,“polyfill":,假的, ,,,,,,,,,“regenerator":,真的, ,,,,,,,,,“moduleName":,“babel-runtime" ,,,,,,,}] ,,,) }
包。json
一,不使用巴贝尔做转义
直接执行npm build 生成的结果。js
执行节点的结果。js
import *从“aliasPerson。/person.js";
从“进口defaultPerson。/person.js";
执行结构完全一样
二,使用巴贝尔做转义
取消如下注释。
执行npm build 生成的结果。js
执行节点的结果。js
原因如下
巴别塔会将,module.exports 所指向的对象的非继承属性遍历并附加到newObj对象中,
并且newObj.default=module.exports
webpack与巴贝尔解析module.exports差异