I am struggling to understand how the tree-shaking feature works in date-fns version 2...
To assist me, I have created a simple project using:
date-fns 2.1.0
webpack 4.39.3
typescript 3.6.2
The project consists of 2 files, one acting as the "library" and the other as the code to run, with the following structure...
import ParseDate from './parse-date'
const parse = new ParseDate();
const result = parse.getExpirationDate({ months: 3 });
console.log(result);
However, even though I only require 6 libraries for tree-shaking to work properly...
import { addYears, addMonths, addWeeks, addDays, addHours, addMinutes } from 'date-fns';
as mentioned in their documentation:
// Without tree-shaking:
import format from 'date-fns/format'
import parse from 'date-fns/parse'
// With tree-shaking:
import { format, parse } from 'date-fns'
Webpack is bundling the entire date-fns library, resulting in a file size of 726Kb !!
> npm run build
> <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8de9ecf9e8d2ebe3fed2f9e8fef9cdbca3bda3bd">[email protected]</a> build C:\Users\balexandre\date_fns_test
> tsc && webpack
Hash: 419a712549fc2309f21e
Version: webpack 4.39.3
Time: 820ms
Built at: 2019-09-09 17:27:36
Asset Size Chunks Chunk Names
bundle.js 726 KiB main [emitted] main
Entrypoint main = bundle.js
chunk {main} bundle.js (main) 441 KiB [entry] [rendered]
> ./src/index.js main
[./src/index.js] 410 bytes {main} [depth 0] [built]
single entry ./src/index.js main
[./src/parse-date.js] 1.27 KiB {main} [depth 1] [built]
cjs require ./parse-date [./src/index.js] 6:35-58
+ 212 hidden modules
What could I be missing? It seems like a straightforward issue but I'm out of ideas :(
The project is available on GitHub for easy review (and git pull) here :)