webpack使用tree shaking示例:

在webpack5中,打包模式production时才开启

javascript 复制代码
module.exports = {
    entry: './src/index.js',
    output: {
        filename: 'main.js',
    },
    mode: 'production',
}

webpack在打包时,tree shaking会自动运行,webpack会解析代码 构建依赖图谱 标记未使用的模块和代码,并在最终打包结果中移除未使用的代码。

javascript 复制代码
webpack.config.js
module.exports = {
    entry: './src/index.js',
    output: {
        filename: 'main.js',
    },
    mode: 'production', // 或者 'production'
}
javascript 复制代码
src/index.js
import { ttt } from './util.js'

function testfn() {
    return 'test'
}

let a = 1
a+=1

src/util.js
export const ttt = '123ttt'
相关推荐
FreeTinker15 小时前
HTML本地存储技术解析:localStorage与sessionStorage的原理、差异与应用场景
前端·html
qq_4523962315 小时前
第十二篇:《全链路监控与可观测性:前端错误追踪与性能分析》
前端
wangruofeng16 小时前
Phosphor Icons 官网源码拆解:URL 即存储、水波动画与 7362 Star 图标库的架构实践
前端·架构·github
BigTopOne16 小时前
WebRTC Native / Android 开发学习资源整理
前端
excel17 小时前
nuxt 3 升级 nuxt 4 报错之 hasInjectionContext
前端
何以解忧,唯有..17 小时前
LangChain 工具调用(Tool Calling)实战指南
java·前端·langchain
软件聚导航18 小时前
「聚小软 AI 助手」技术升级:从数据库检索到 RAG 知识库问答
前端·数据库·mysql·微信小程序·小程序·ai编程·rag
恋猫de小郭19 小时前
看懂大模型架构术语,帮助你理解目前常见的大模型开源架构
前端·人工智能·ai编程
yma1619 小时前
通过提示词实现GitHub Pages 和 Nginx 双部署竟然这么简单?
前端
前端 贾公子19 小时前
第09章:上下文与记忆 (2)
java·服务器·前端