webpack

devtool

  • development
 devtool: "cheap-module-eval-source-map"
  • production
 devtool: "cheap-module-source-map"

HMR

1.配置hot,hotOnly
devServer: {
        contentBase: './dist', //服务器要起在哪个文件夹下
        open: true,
        hot: true,
        hotOnly: true
    }
2.引入插件
plugins: [
        new webpack.HotModuleReplacementPlugin()
    ],

polyfill(业务)

1.引入babel
{
    test: /\.js$/,
     exclude: /node_modules/,
     loader: 'babel-loader'
 }
 2.文件头部
import "@babel/polyfill";
3..babelrc文件配置
{
   
    "presets": [
        ["@babel/preset-env", {
            "targets": {
                "chrome": "67" chrome在67版本以上不转换
            },
            "useBuiltIns": "usage" //按需添加辅助特征
        }],
        ["@babel/preset-react"]
    ]
}

transform-run-time(内库,ui等)

1.
 {
     test: /\.js$/,
       exclude: /node_modules/,
       loader: 'babel-loader'
   }
   2, 不需import "@babel/polyfill";
   3.配置
   {
    // "plugins": [["@babel/plugin-transform-runtime", {
	//     "absoluteRuntime": false,
	//     "corejs": 2,
	//     "helpers": true,
	//     "regenerator": true,
	//     "useESModules": false
	// }]]
	}
   

加前缀

 {
        test: /\.scss$/,
        use: [
            'style-loader', 
            {
                loader: 'css-loader',
                options: {
                    importLoaders: 2
                }
            }, 
            'sass-loader', 
            'postcss-loader'
        ]
    }
    2.postcss.config.js
    module.exports = {
	    plugins: [
	        require('autoprefixer')
	    ]
	  }

tree shaking

  • mode: ‘development’
1.添加配置
optimization: {
        usedExports: true
    },
2.package.json
"sideEffects": false,  //配置哪些引入不需要tree shaking的
  
  • mode: ‘production’
只需要配置
"sideEffects": false,
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值