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的性能提升

相关推荐
奔跑的web.9 小时前
TypeScript Enum 类型入门:从基础到实战
前端·javascript·typescript
盐真卿9 小时前
python2
java·前端·javascript
梦梦代码精10 小时前
BuildingAI vs Dify vs 扣子:三大开源智能体平台架构风格对比
开发语言·前端·数据库·后端·架构·开源·推荐算法
seabirdssss11 小时前
《bootstrap is not defined 导致“获取配置详情失败”?一次前端踩坑实录》
前端·bootstrap·html
kgduu11 小时前
js之表单
开发语言·前端·javascript
谢尔登13 小时前
Vue3 响应式系统——computed 和 watch
前端·架构
愚公移码13 小时前
蓝凌EKP产品:主文档权限机制浅析
java·前端·数据库·蓝凌
欣然~14 小时前
法律案例 PDF 批量转 TXT 工具代码
linux·前端·python
一个小废渣14 小时前
Flutter Web端网络请求跨域错误解决方法
前端·flutter
符文师15 小时前
css3 新特性
前端·css3