Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jmblog committed Nov 25, 2016
0 parents commit 1f4155b
Show file tree
Hide file tree
Showing 13 changed files with 164 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
node_modules
*.log
2 changes: 2 additions & 0 deletions README.md
@@ -0,0 +1,2 @@
# moment.js optimization

10 changes: 10 additions & 0 deletions contextReplacementPlugin/bundle.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions contextReplacementPlugin/bundle.js.map

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions contextReplacementPlugin/webpack.config.js
@@ -0,0 +1,22 @@
const path = require('path');
const webpack = require('webpack');

module.exports = {
devtool: 'source-map',
entry: {
bundle: [path.resolve(__dirname, '../index.js')],
},
output: {
path: path.resolve(__dirname, './'),
filename: '[name].js',
library: '[name]',
},
plugins: [
new webpack.optimize.UglifyJsPlugin(),
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /ja|it/),
],
resolve: {
root: path.resolve(__dirname, './'),
modulesDirectories: ['node_modules'],
},
};
9 changes: 9 additions & 0 deletions ignorePlugin/bundle.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ignorePlugin/bundle.js.map

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions ignorePlugin/webpack.config.js
@@ -0,0 +1,22 @@
const path = require('path');
const webpack = require('webpack');

module.exports = {
devtool: 'source-map',
entry: {
bundle: [path.resolve(__dirname, '../index.js')],
},
output: {
path: path.resolve(__dirname, './'),
filename: '[name].js',
library: '[name]',
},
plugins: [
new webpack.optimize.UglifyJsPlugin(),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), // Ignore all optional deps of moment.js
],
resolve: {
root: path.resolve(__dirname, './'),
modulesDirectories: ['node_modules'],
},
};
23 changes: 23 additions & 0 deletions index.js
@@ -0,0 +1,23 @@
const assert = require('assert');
const moment = require('moment');
require('moment/locale/ja');
require('moment/locale/it');

const oneDay = '2016-11-25T15:43:21';

describe('localized moment', function() {
it('should be shown in English', function() {
moment.locale('en');
assert(moment(oneDay).format('LLLL') === 'Friday, November 25, 2016 3:43 PM')
});

it('should be shown in Japanese', function() {
moment.locale('ja');
assert(moment(oneDay).format('LLLL') === '2016年11月25日午後3時43分 金曜日')
});

it('should be shown in Italian', function() {
moment.locale('it');
assert(moment(oneDay).format('LLLL') === 'Venerdì, 25 novembre 2016 15:43')
});
});
14 changes: 14 additions & 0 deletions normal/bundle.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions normal/bundle.js.map

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions normal/webpack.config.js
@@ -0,0 +1,21 @@
const path = require('path');
const webpack = require('webpack');

module.exports = {
devtool: 'source-map',
entry: {
bundle: [path.resolve(__dirname, '../index.js')],
},
output: {
path: path.resolve(__dirname, './'),
filename: '[name].js',
library: '[name]',
},
plugins: [
new webpack.optimize.UglifyJsPlugin(),
],
resolve: {
root: path.resolve(__dirname, './'),
modulesDirectories: ['node_modules'],
},
};
36 changes: 36 additions & 0 deletions package.json
@@ -0,0 +1,36 @@
{
"name": "how-to-optimize-momentjs-with-webpack",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build:normal": "webpack --config normal/webpack.config.js",
"build:contextReplacementPlugin": "webpack --config contextReplacementPlugin/webpack.config.js",
"build:ignorePlugin": "webpack --config ignorePlugin/webpack.config.js",
"build": "npm-run-all build:*",
"analyze:normal": "npm run build:normal && source-map-explorer normal/bundle.js",
"analyze:contextReplacementPlugin": "npm run build:contextReplacementPlugin && source-map-explorer contextReplacementPlugin/bundle.js",
"analyze:ignorePlugin": "npm run build:ignorePlugin && source-map-explorer ignorePlugin/bundle.js",
"analyze": "npm-run-all --parallel analyze:*",
"test:normal": "mocha normal/bundle.js",
"test:contextReplacementPlugin": "mocha contextReplacementPlugin/bundle.js",
"test:ignorePlugin": "mocha ignorePlugin/bundle.js",
"test": "npm-run-all build test:*",
"gzip-size:normal": "gzip-size normal/bundle.js | pretty-bytes",
"gzip-size:contextReplacementPlugin": "gzip-size contextReplacementPlugin/bundle.js | pretty-bytes",
"gzip-size:ignorePlugin": "gzip-size ignorePlugin/bundle.js | pretty-bytes",
"gzip-size": "npm-run-all gzip-size:*"
},
"keywords": [],
"author": "",
"license": "MIT",
"devDependencies": {
"gzip-size-cli": "^1.0.0",
"mocha": "^3.2.0",
"moment": "^2.16.0",
"npm-run-all": "^3.1.1",
"pretty-bytes-cli": "^2.0.0",
"source-map-explorer": "^1.3.3",
"webpack": "^1.13.3"
}
}

0 comments on commit 1f4155b

Please sign in to comment.