@babel/plugin-transform-runtime 到底是什么?
// 此文件相当于babel-loader的options选项{"presets": [["@babel/preset-env",{// useBuiltIns配置polyfill和targets使用,// false 此时不对 polyfill 做操作,无视配置的浏览器兼容,引入所有的 polyfill// usage会根据配置的浏览器兼容,以及你代码中用到的 API 来进行 polyfill,实现了按需添加// entry 根据配置的浏览器兼容, 引入浏览器不兼容的 polyfill"useBuiltIns": "usage","targets": { // 环境chrome67以上支持ES6"chrome": "67"}}]], // 语法的变换 // 8.x以下配置babel-preset-env"plugins": [["@babel/plugin-transform-runtime",{"absoluteRuntime": false,// 相较于preset-env改变全局变量,corejs会引入单独的模块,生成新的变量。例如引入_Promise,替换ES6的Promise// corejs2只处理包装类型的方法,如Array.inclues;corejs3会处理实例的方法,如[].includes"corejs": 2, // 默认false,如果是2,需安装@babel/runtime-corejs2"helpers": true,"regenerator": true,"useESModules": false}],// 模块异步引入 import(xxx).then({ default: _ } => {});// 动态import插件,但不支持魔法注释// [// "dynamic-import-webpack" // babel-plugin-dynamic-import-webpack// ],// 这是官方动态import插件,支持魔法注释["@babel/plugin-syntax-dynamic-import"]]}
// .babelrc 编辑器// 此文件相当于babel-loader的options选项{"presets": [["@babel/preset-env",{"useBuiltIns": "usage","corejs": 2 // 不确定plugin-transform-runtime用了corejs2/3后这里还需不需要corejs}]],"plugins": [["@babel/plugin-transform-runtime",{"corejs": 2}]],// 严格区分 commonJS 文件和 ES6 文件"sourceType": "unambiguous"}
“sourceType”: “unambiguous”解决Cannot assign to read only property ‘exports’ of object ‘#
