Skip to content

Commit

Permalink
Add more replacements to decrease minified filesize
Browse files Browse the repository at this point in the history
  • Loading branch information
jackocnr committed Oct 6, 2018
1 parent 49c9dc3 commit e862d2e
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/grunt
/build
/Gruntfile.js
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function(grunt) {
// just images
grunt.registerTask('img', ['responsive_images:retina', 'exec:evenizer', 'responsive_images:regular', 'sprite', 'imagemin']);
// just javascript (babel must go before we add the wrapper, to keep it's generated methods inside, so not globals)
grunt.registerTask('js', ['eslint', 'template:jsAddVersion', 'babel', 'concat', 'uglify', 'replace:one', 'replace:two']);
grunt.registerTask('js', ['eslint', 'template:jsAddVersion', 'babel', 'concat', 'uglify', 'replace']);

// build examples
grunt.registerTask('examples', ['template']);
Expand Down
2 changes: 1 addition & 1 deletion build/js/intlTelInput-jquery.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/js/intlTelInput.min.js

Large diffs are not rendered by default.

173 changes: 144 additions & 29 deletions grunt/replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ module.exports = function(grunt) {

/***********
* PRIVATE METHODS
* (special treatment for the _init method, which is a subset of other method names)
* Ignore _init method, which is a subset of other method names, and is used in different ways
* Note: can't do public methods, as they need to be called as is
***********/
one: {
options: {
patterns: [
// Note: _a is now reserved for step two
{
match: /_processCountryData/g,
replacement: '_b'
Expand All @@ -17,12 +19,21 @@ module.exports = function(grunt) {
}, {
match: /_processAllCountries/g,
replacement: '_d'
}, {
match: /_translateCountriesByLocale/g,
replacement: '_d0'
}, {
match: /_countryNameSort/g,
replacement: '_d1'
}, {
match: /_processCountryCodes/g,
replacement: '_d2'
}, {
match: /_processPreferredCountries/g,
replacement: '_e'
}, {
match: /_createEl/g,
replacement: '_e2'
}, {
match: /_generateMarkup/g,
replacement: '_f'
Expand All @@ -36,14 +47,20 @@ module.exports = function(grunt) {
match: /_initListeners/g,
replacement: '_i'
}, {
match: /_initDropdownListeners/g,
match: /_initHiddenInputListener/g,
replacement: '_i0'
}, {
match: /_getClosestLabel/g,
replacement: '_i1'
}, {
match: /_initRequests/g,
match: /_initDropdownListeners/g,
replacement: '_i2'
}, {
match: /_loadAutoCountry/g,
match: /_initRequests/g,
replacement: '_i3'
}, {
match: /_loadAutoCountry/g,
replacement: '_i4'
}, {
match: /_initKeyListeners/g,
replacement: '_j'
Expand All @@ -53,15 +70,27 @@ module.exports = function(grunt) {
}, {
match: /_initFocusListeners/g,
replacement: '_l'
}, {
match: /_removeEmptyDialCode/g,
replacement: '_l2'
}, {
match: /_getNumeric/g,
replacement: '_m'
}, {
match: /_trigger/g,
replacement: '_m2'
}, {
match: /_showDropdown/g,
replacement: '_n'
}, {
match: /_toggleClass/g,
replacement: '_n2'
}, {
match: /_setDropdownPosition/g,
replacement: '_o'
}, {
match: /_getClosestListItem/g,
replacement: '_o2'
}, {
match: /_bindDropdownListeners/g,
replacement: '_p'
Expand All @@ -83,6 +112,9 @@ module.exports = function(grunt) {
}, {
match: /_updateFlagFromNumber/g,
replacement: '_v'
}, {
match: /_isRegionlessNanp/g,
replacement: '_w'
}, {
match: /_highlightListItem/g,
replacement: '_x'
Expand All @@ -94,28 +126,31 @@ module.exports = function(grunt) {
replacement: '_z'
}, {
match: /_updatePlaceholder/g,
replacement: '_aa'
replacement: '_0'
}, {
match: /_selectListItem/g,
replacement: '_ab'
replacement: '_1'
}, {
match: /_closeDropdown/g,
replacement: '_ac'
replacement: '_2'
}, {
match: /_scrollTo/g,
replacement: '_ad'
replacement: '_3'
}, {
match: /_updateDialCode/g,
replacement: '_ae'
replacement: '_4'
}, {
match: /_getDialCode/g,
replacement: '_af'
replacement: '_5'
}, {
match: /_getFullNumber/g,
replacement: '_ag'
replacement: '_6'
}, {
match: /_beforeSetNumber/g,
replacement: '_ah'
replacement: '_7'
}, {
match: /_triggerCountryChange/g,
replacement: '_8'
}
]
},
Expand All @@ -127,59 +162,139 @@ module.exports = function(grunt) {


/***********
* FIELDS ON "this"
* INLINE PRIVATE METHODS
***********/
two: {
options: {
patterns: [
{
match: /.telInput/g,
match: /_handleMouseoverCountryList/g,
replacement: '_a0'
}, {
match: /_handleClickCountryList/g,
replacement: '_a1'
}, {
match: /_handleClickOffToClose/g,
replacement: '_a2'
}, {
match: /_handleKeydownOnDropdown/g,
replacement: '_a3'
}, {
match: /_handleWindowScroll/g,
replacement: '_a4'
}, {
match: /_handleMousedownFocusEvent/g,
replacement: '_a5'
}, {
match: /_handleKeypressPlusEvent/g,
replacement: '_a6'
}, {
match: /_handleFocusEvent/g,
replacement: '_a7'
}, {
match: /_handleSubmitOrBlurEvent/g,
replacement: '_a8'
}, {
match: /_handleLabelClick/g,
replacement: '_a9'
}, {
match: /_handleClickSelectedFlag/g,
replacement: '_a10'
}, {
match: /_handleFlagsContainerKeydown/g,
replacement: '_a11'
}, {
match: /_handleKeyupEvent/g,
replacement: '_a12'
}, {
match: /_handleClipboardEvent/g,
replacement: '_a13'
}, {
match: /_handleHiddenInputSubmit/g,
replacement: '_a14'
}
]
},
files: {
'tmp/two.min.js': 'tmp/one.min.js',
'tmp/two-jquery.min.js': 'tmp/one-jquery.min.js',
}
},


/***********
* INSTANCE FIELDS
* Note: avoid option names as that will break things!
***********/
three: {
options: {
patterns: [
{
match: /\.telInput/g,
replacement: '.a'
}, {
match: /.options/g,
match: /\.activeItem/g,
replacement: '.b'
}, {
match: /.hadInitialPlaceholder/g,
match: /\.highlightedItem/g,
replacement: '.c'
}, {
match: /\.options/g,
replacement: '.d'
}, {
match: /\.hadInitialPlaceholder/g,
replacement: '.e'
}, {
match: /.isMobile/g,
match: /\.isMobile/g,
replacement: '.g'
}, {
match: /.resolveAutoCountryPromise/g,
match: /\.resolveAutoCountryPromise/g,
replacement: '.h'
}, {
match: /.resolveUtilsScriptPromise/g,
match: /\.rejectAutoCountryPromise/g,
replacement: '.i'
}, {
match: /.defaultCountry/g,
match: /\.resolveUtilsScriptPromise/g,
replacement: '.i0'
}, {
match: /\.rejectUtilsScriptPromise/g,
replacement: '.i1'
}, {
match: /\.defaultCountry/g,
replacement: '.j'
}, {
match: /.flagsContainer/g,
match: /\.flagsContainer/g,
replacement: '.k'
}, {
match: /.selectedFlagInner/g,
match: /\.selectedFlagInner/g,
replacement: '.l'
}, {
match: /.countryList/g,
match: /\.countryList/g,
replacement: '.m'
}, {
match: /.countries/g,
match: /\.countries/g,
replacement: '.p'
}, {
match: /.countryCodes/g,
match: /\.countryCodes/g,
replacement: '.q'
}, {
match: /.selectedCountryData/g,
match: /\.selectedCountryData/g,
replacement: '.s'
}, {
match: /.selectedDialCode/g,
match: /\.selectedDialCode/g,
replacement: '.t'
}, {
match: /\.dropdownArrow/g,
replacement: '.u'
}, {
match: /\.hiddenInput/g,
replacement: '.w'
}
]
},
files: {
'build/js/intlTelInput.min.js': 'tmp/one.min.js',
'build/js/intlTelInput-jquery.min.js': 'tmp/one-jquery.min.js',
'build/js/intlTelInput.min.js': 'tmp/two.min.js',
'build/js/intlTelInput-jquery.min.js': 'tmp/two-jquery.min.js',
}
}
};
Expand Down

0 comments on commit e862d2e

Please sign in to comment.