reduce webpack bundle size: replace moment with date-rns (#2035)

Replace the moment.js date library with a smaller one (date-fns).
Has the added advantage that we no longer need to supress all of
moment's locales.
This commit is contained in:
Risha Mars 2019-01-04 15:51:22 -05:00 committed by GitHub
parent fcd7c9bf5c
commit a397393996
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 461 additions and 420 deletions

View File

@ -1,3 +1,4 @@
import { distanceInWordsToNow, subSeconds } from 'date-fns';
import BaseTable from './BaseTable.jsx';
import CallToAction from './CallToAction.jsx';
import Card from '@material-ui/core/Card';
@ -21,7 +22,6 @@ import _map from 'lodash/map';
import _mapKeys from 'lodash/mapKeys';
import _sumBy from 'lodash/sumBy';
import { incompleteMeshMessage } from './util/CopyUtils.jsx';
import moment from 'moment';
import { withContext } from './util/AppContext.jsx';
const serviceMeshDetailsColumns = [
@ -118,12 +118,12 @@ class ServiceMesh extends React.Component {
name: component,
pods: _map(byDeployName[deployName], p => {
let uptimeSec = !p.uptime ? 0 : p.uptime.split(".")[0];
let uptime = moment.duration(parseInt(uptimeSec, 10) * 1000);
let uptime = distanceInWordsToNow(subSeconds(Date.now(), parseInt(uptimeSec, 10)));
return {
name: p.name,
value: getPodClassification(p),
uptime: uptime.humanize(),
uptime,
uptimeSec
};
})

View File

@ -11,8 +11,8 @@
"d3-force": "^2.0.0",
"d3-format": "^1.3.2",
"d3-selection": "^1.3.2",
"date-fns": "^1.30.1",
"lodash": "4.17.10",
"moment": "2.22.2",
"path": "0.12.7",
"prop-types": "15.6.1",
"react": "16.5.0",
@ -49,7 +49,6 @@
"jest-dot-reporter": "1.0.7",
"jest-enzyme": "7.0.0",
"lodash-webpack-plugin": "^0.11.5",
"moment-locales-webpack-plugin": "^1.0.7",
"react-test-renderer": "16.5.2",
"sinon": "7.0.0",
"sinon-stub-promise": "4.0.0",

View File

@ -1,7 +1,6 @@
/* global require, module, __dirname */
const path = require('path');
const MomentLocalesPlugin = require('moment-locales-webpack-plugin');
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
// uncomment here and in plugins to analyze bundle size
@ -65,7 +64,6 @@ module.exports = {
// 'chain': true,
'collections': true,
'paths': true
}),
new MomentLocalesPlugin()
})
]
}

File diff suppressed because it is too large Load Diff