Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1f4155b
Showing
13 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# moment.js optimization | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'], | ||
}, | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') | ||
}); | ||
}); |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |