上一篇:【webpack5修行之道】第12篇:性能优化-代码分隔
懒加载
修改index.html,添加一个按钮
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>webpack</title>
</head>
<body>
<button id="btn">按钮</button>
</body>
</html>
修改index.js,webpackChunkName能够指定chunk的名字
console.log('index.js 被加载了')
document.getElementById('btn').onclick = () => {
import( /* webpackChunkName: 'mathfile' */'./math.js').then(({say})=>