[Tools] Target specific browsers with babel-preset-env and the babel pollyfill (browserslist)
The and with tools Target babel ENV specific
2023-09-14 08:59:14 时间
Converting all of our modern JavaScript into ES5 compatible syntax is a great way to use modern features while targeting older browsers. What happens when the browsers natively support these language features? Then it no longer makes sense to transform that code or to include polyfills that will go unused. In this lesson, we’ll add the @babel/polyfill
package and configure babel-preset-env
To reduce the polyfill size, we can targeting morden browser by using browserlist:
webpack.config.base.js
const path = require('path') const HtmlWebpackPlugin = require('html-webpack-plugin') module.exports = { entry: './src/index.js', output: { path: path.join(__dirname, 'dist'), filename: 'app.bundle.js' }, module: { rules: [ { test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/, options: { presets: [['@babel/preset-env', { targets: [ 'last 2 versions', 'not dead', 'not < 2%' ], useBuiltIns: 'entry' }], '@babel/preset-react'], plugins: [ 'react-hot-loader/babel', '@babel/plugin-proposal-class-properties' ] } }, { test: /\.css$/, use: ['style-loader', 'css-loader'], exclude: /node_modules/ } ] }, plugins: [new HtmlWebpackPlugin({ template: './src/index.html' })] }
You can see the supported browserlist by running:
npx browserlist "last 2 versions, not dead, not < 2%"
It will return a llst of supported browsers.
Together with bundler-analyser we can see the bundle size:
webpack.config.prod.js
const merge = require('webpack-merge') const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer') const baseConfig = require('./webpack.config.base') module.exports = merge(baseConfig, { mode: 'production', plugins: [new BundleAnalyzerPlugin({ analyzerMode: 'static', openAnalyzer: false, reportFilename: 'bundle_sizes.html' })], externals: { react: 'React', 'react-dom': 'ReactDOM' } })
相关文章
- ORA-22956: The set contains no elements ORACLE 报错 故障修复 远程处理
- ORA-27044: unable to write the header block of file ORACLE 报错 故障修复 远程处理
- ORA-31605: the following was returned from string in routine string: LPX-number: string ORACLE 报错 故障修复 远程处理
- ORA-46012: The value of the “privilege” element is too long. ORACLE 报错 故障修复 远程处理
- ORA-48411: The trace files exceeds the maximum number [string] ORACLE 报错 故障修复 远程处理
- ORA-48442: The control parameter number exceeds the maximum number [string] ORACLE 报错 故障修复 远程处理
- ORA-48489: The input exceeds the maximum length [string] ORACLE 报错 故障修复 远程处理
- ORA-55567: The _highthreshold_undoretention value should be at least string based on the current undo retention settings. ORACLE 报错 故障修复 远程处理
- ORA-13614: The template string is not compatible with the current advisor. ORACLE 报错 故障修复 远程处理
- ORA-13621: The task_or object string is marked as a template and cannot perform the requested operation. ORACLE 报错 故障修复 远程处理
- MyD MySQL: The Innovative Database Management System for Improved Performance and Security(mydmysql)
- Unlocking the Power of Data with MYSQL and ADO: A Comprehensive Guide(mysqlado)
- Power Up Your Projects with Linux PP: Exploring the Best Tools and Techniques(linuxpp)
- Unlocking the Mystery of Oracle Locks: Understanding Their Purpose and Function(oraclelock)
- Push Your Linux Skills to the Next Level with These Tips and Tricks(linuxpush)
- Exploring the Origins and Significance of the MySQL Name(mysql名字)
- Exploring the Source Code of MongoDB Project: A Comprehensive Guide(mongodb项目源码)
- Exploring the Importance of Character Encoding and Primary Keys in MySQL(mysql字符主键)
- Mastering the Art of Process Management on Linux with C and Kill Commands(linuxckill)
- Exploring the Power of Linux with C Code: Tips Tricks and Best Practices(linuxc代码)
- Exploring the Distinctive Traits of MongoDB: A Comprehensive Overview(mongodb的特点)
- Exploring the Power of macOS for PDF Management and Beyond(macospdf)
- Exploring the Beautiful Alliance of Linux and Monaco: A Powerful Match for Tech Innovators(linuxmonaco)
- Exploring the Features and Benefits of MySQL 5.5(mysql5.5)
- Discover the Power of Linux with YLMF: The UserFriendly Operating System(linuxylmf)
- Unleash Your Inner Gamer with Linux and L4D2: Discover the Ultimate Gaming Experience!(linuxl4d2)