$ npm i --save date-fns
$ npm i --save-dev babel-plugin-date-fns
Transforms
import { distanceInWordsToNow, differenceInYears, format } from 'date-fns';
roughly to
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
import differenceInYears from 'date-fns/difference_in_years';
import format from 'date-fns/format';
{
"plugins": ["date-fns"],
"presets": ["es2015"]
}
module: {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
presets: ['es2015'],
plugins: ['date-fns'],
},
}],
}
Heavily inspired by babel-plugin-lodash and babel-plugin-recharts.