question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enable tree shaking for date-fns

See original GitHub issue
  • Introduce modules index file and add it to package.json as main
  • Add docs

See http://www.2ality.com/2015/12/webpack-tree-shaking.html

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:7
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
existentialismcommented, Nov 21, 2016

Somewhat relevant… but I created a babel plugin that saves some keystrokes. It translates:

import { distanceInWordsToNow, differenceInYears, format } from 'date-fns';

to

import distanceInWordsToNow from 'date-fns/distanceInWordsToNow';
import differenceInYears from 'date-fns/differenceInYears';
import format from 'date-fns/format';

https://github.com/existentialism/babel-plugin-date-fns

Usual caveat of it working fine for our internal projects, but it could definitely use more feedback/usage.

(Also happy to transfer over to the date-fns org if interested!)

4reactions
avocadowastakencommented, Oct 24, 2016

@kossnocorp 👍 it would be great to use like import {parse, format, max, min} from 'date-fns' in future without worrying about bundle size

Read more comments on GitHub >

github_iconTop Results From Across the Web

date-fns 2 - can't get tree-shaking to work - Stack Overflow
To make tree-shaking work you have to configure TypeScript to compile to ES Modules instead of CommonJS and also enable production mode in ......
Read more >
Tree shaking issue in 2.17 · Issue #2207 · date-fns ... - GitHub
I'm using date-fns in two projects (without additional locales) and when I upgraded to 2.17 the bundle size went to ~200Kb.
Read more >
Treeshaking Date-Fns with Webpack 4 - The Aurelia Discourse
Tree -shaking creates problems that should not exist in first place. You can turn it off in webpack config. At least Aurelia v1...
Read more >
You can also look to date-fns. It has good tree shaking support.
If I am looking for python-dateutil.parser.parse in JavaScript of DateTime string of unknown format; what is the best library, for both Node.js environment ......
Read more >
ECMAScript Modules in date-fns v2
In this post, I tell about ECMAScript Modules support in date-fns v2 that among other goodies enables tree-shaking out of the box.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found