⚠️ The current master is for v2 pre-release version of date-fns. See the plugin of v1 version.
$ npm i --save date-fns
$ npm i --save-dev babel-plugin-date-fns
Transforms
import { formatDistance, differenceInYears, format } from 'date-fns';
roughly to
import formatDistance from 'date-fns/formatDistance';
import differenceInYears from 'date-fns/differenceInYears';
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.