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

相关推荐
青稞儿几秒前
面试题高频之token无感刷新(vue3+node.js)
vue.js·node.js
diygwcom6 分钟前
electron-updater实现electron全量版本更新
前端·javascript·electron
Hello-Mr.Wang23 分钟前
vue3中开发引导页的方法
开发语言·前端·javascript
程序员凡尘1 小时前
完美解决 Array 方法 (map/filter/reduce) 不按预期工作 的正确解决方法,亲测有效!!!
前端·javascript·vue.js
编程零零七4 小时前
Python数据分析工具(三):pymssql的用法
开发语言·前端·数据库·python·oracle·数据分析·pymssql
(⊙o⊙)~哦6 小时前
JavaScript substring() 方法
前端
无心使然云中漫步7 小时前
GIS OGC之WMTS地图服务,通过Capabilities XML描述文档,获取matrixIds,origin,计算resolutions
前端·javascript
Bug缔造者7 小时前
Element-ui el-table 全局表格排序
前端·javascript·vue.js
xnian_7 小时前
解决ruoyi-vue-pro-master框架引入报错,启动报错问题
前端·javascript·vue.js
麒麟而非淇淋8 小时前
AJAX 入门 day1
前端·javascript·ajax