webpack优化构建速度示例-resolve.extensions:

当项目不仅仅包含.js或.json文件,还包含其他类型文件(如.ts、.vue、.css)作为模块时,配置resolve.extensions可以不必要的文件搜索提高性能。

c 复制代码
src/index.ts
import { someFuction } from './module'

someFuction()
c 复制代码
src/module.ts

import {otherSomeFuction} from './othermodule'


export const someFuction = otherSomeFuction
c 复制代码
src/othermodule.ts
export const otherSomeFuction = () => {
    console.log('otherSomeFuction...')
}

优化前

c 复制代码
webpack.config.js

const config = {
    entry: './src/index.ts',
    output: {
        filename: 'main.js'
    },
  mode: 'development',
  resolve: {  
    extensions: [ '.js', '.json', '.jsx', '.tsx', '.ts'], 
  },  
  module: {
    rules: [
      {
        test: /\.ts$/,
        loader: 'ts-loader'
      }
    ]
  }
}

module.exports = config;

优化后

c 复制代码
webpack.config.js

const config = {
    entry: './src/index.ts',
    output: {
        filename: 'main.js'
    },
  mode: 'development',
  resolve: {  
    extensions: [ '.ts', '.tsx', '.js', '.jsx', '.json'], 
  },  
  module: {
    rules: [
      {
        test: /\.ts$/,
        loader: 'ts-loader'
      }
    ]
  }
}

module.exports = config;

可以看到优化resolve.extensions的顺序,简单的三个小模块的打包就带来了1508-1467=41ms的性能提升

相关推荐
Codebee1 分钟前
使用Qoder 改造前端UI/UE升级改造实践:从传统界面到现代化体验的华丽蜕变
前端·人工智能
叫我詹躲躲5 分钟前
开发提速?Vue3模板隐藏技巧来了
前端·vue.js·ai编程
华仔啊5 分钟前
面试都被问懵了?CSS 的 flex:1 和 flex:auto 真不是一回事!90%的人都搞错了
前端·javascript
前端康师傅7 分钟前
JavaScript 函数详解
前端·javascript
金金金__10 分钟前
antd v5 support React is 16 ~ 18. see https://u.ant.design/v5-for-19 for...
前端
会豪11 分钟前
工业仿真(simulation)--前端(二)-资源管理器
前端
@小红花1 小时前
从0到1学习Vue框架Day03
前端·javascript·vue.js·学习·ecmascript
前端与小赵1 小时前
vue3中 ref() 和 reactive() 的区别
前端·javascript·vue.js
魔云连洲1 小时前
Vue的响应式底层原理:Proxy vs defineProperty
前端·javascript·vue.js
专注VB编程开发20年1 小时前
CSS定义网格的列模板grid-template-columns什么意思,为什么要用这么复杂的单词
前端·css