Webpack4+Babel7+ES6兼容IE8的实现(2)

{ "devDependencies": { "@babel/core": "^7.2.2", "@babel/plugin-transform-runtime": "^7.2.0", "@babel/preset-env": "^7.1.0", "@babel/runtime": "^7.3.4", "babel-loader": "^8.0.4", "core-js": "^3.0.1", "uglifyjs-webpack-plugin": "^2.0.1", "webpack": "^4.20.2", "webpack-cli": "^3.1.2", "webpack-dev-server": "^3.1.9", "webpack-merge": "^4.1.4" } }

webpack配置

{ module: { rules: [ { test: /\.js$/, exclude: /(node_modules|bower_components)/, use: { loader: 'babel-loader', options: { presets: [ '@babel/preset-env' ], plugins: [ [ '@babel/plugin-transform-runtime' ], [ // 笔者为了兼容IE8才用了这个插件,代价是不能tree shaking // 没有IE8兼容需求的同学可以把这个插件去掉 '@babel/plugin-transform-modules-commonjs' ] ] } } } ] }, optimization: { minimizer: [ new UglifyJsPlugin({ sourceMap: true, uglifyOptions: { ie8: true, } }) ] } }

入口文件按需引入缺失的API

require('core-js/features/object/define-property') require('core-js/features/object/create') require('core-js/features/object/assign') require('core-js/features/array/for-each') require('core-js/features/array/index-of') require('core-js/features/function/bind') require('core-js/features/promise')

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/975202fb77bf95529ca1c7a5c9216544.html