I am currently working on a large project that involves TypeScript.
Various attempts have been made to optimize the use of lodash in my project.
Before making any conclusions, I believe it is important to review the outcomes of my efforts.
The command I use for building is
build command
ng build --stats-json
webpack-bundle-analyzer {{stats.json path}}
custom_loadsh.ts
export { forEach } from 'lodash/forEach';
export { cloneDeep } from 'lodash/cloneDeep';
...
..
.
app.component.ts
import * as _ from './custom_lodash';
export class AppComponent implements OnInit {
...
ngOnInit() {
let data = {
test: 1
};
let data2 = _.cloneDeep(data);
}
...
}
Instead of importing the entire lodash library through custom_lodash, I have selectively imported specific modules.
https://i.stack.imgur.com/CGcNF.png
In reality, the example code provided above may differ slightly from the actual project, but the overall setup remains consistent.
I am curious about why tree shaking with lodash is not successful.
You can find more information on this topic on the following site: https://medium.com/@martin_hotell/tree-shake-lodash-with-webpack-jest-and-typescript-2734fa13b5cd