小编Bil*_*rry的帖子

未引用的默认参数是否会被 webpack 自动摇出树?

如果之前有人问过这个问题,我必须道歉,但我无法在网上或在与 tree shake 相关的 webpack 文档中找到答案。

树摇动如何使用默认参数进行工作?对于上下文:我特别关心 tree-shaking 的 webpack 实现如何处理默认参数。

给出以下假设的应用程序结构:

/
|_ dependency/
| |
| |_ dependency.js
| |_ moderatelyLargeFile.js
|
|
|_src/
  |
  |_ application.js
  |_ someSmallFile.js
Run Code Online (Sandbox Code Playgroud)

以及每个文件中的以下代码:

dependency.js

import moderatelyLargeFile from './moderatelyLargeFile.js';
import { someParsingFunction1, someParsingFunction2 } from 'somewhere-else-dependency';

export default function parseSomeFile(file = moderatelylargeFile) {
  let parsedResult = { ...someParsingFunction1(file), ...someParsingFunction2(file) };
  return parsedResult;
}
Run Code Online (Sandbox Code Playgroud)

application.js

import parseSomeFile from './dependency/dependency.js';
import someSmallFile from './someSmallFile.js'
let result = parseSomeFile(someSmallFile);
// Do other application stuff with …
Run Code Online (Sandbox Code Playgroud)

javascript webpack tree-shaking

6
推荐指数
1
解决办法
58
查看次数

标签 统计

javascript ×1

tree-shaking ×1

webpack ×1