From 89b3fe2926a8660af4df3319a558db8fbcddd4a8 Mon Sep 17 00:00:00 2001 From: Max Huang <risonhuang@gmail.com> Date: Thu, 15 Sep 2016 22:58:26 +1000 Subject: [PATCH] [Issue-94] Use webpack to build vanilla JS bundle --- gulp-tasks/build.js | 16 +--------------- gulp-tasks/webpack.js | 15 ++++++++++++--- src/Cleave.js | 20 +++++++++----------- src/build/expose.js | 21 --------------------- src/build/prefix.js | 1 - src/build/suffix.js | 1 - src/common/DefaultProperties.js | 5 ++--- src/shortcuts/CreditCardDetector.js | 5 ++--- src/shortcuts/DateFormatter.js | 5 ++--- src/shortcuts/NumeralFormatter.js | 4 +--- src/shortcuts/PhoneFormatter.js | 5 ++--- 11 files changed, 31 insertions(+), 67 deletions(-) delete mode 100644 src/build/expose.js delete mode 100644 src/build/prefix.js delete mode 100644 src/build/suffix.js diff --git a/gulp-tasks/build.js b/gulp-tasks/build.js index 7c3eac1b..3dcb82fb 100644 --- a/gulp-tasks/build.js +++ b/gulp-tasks/build.js @@ -49,20 +49,6 @@ gulp.task('min-no-mangle', function () { .pipe(gulp.dest(path.join(paths.dist))); }); -gulp.task('js', function () { - return gulp.src([ - path.join(paths.src, paths.build, 'prefix.js'), - path.join(paths.src, 'Cleave.js'), - path.join(paths.src, paths.utils, '**/*.js'), - path.join(paths.src, paths.common, '**/*.js'), - path.join(paths.src, paths.shortcuts, '**/*.js'), - path.join(paths.src, paths.build, 'expose.js'), - path.join(paths.src, paths.build, 'suffix.js') - ]) - .pipe(concat('cleave.js')) - .pipe(gulp.dest(paths.dist)); -}); - gulp.task('js:angular', function () { return gulp.src([ path.join(paths.dist, 'cleave.js'), @@ -74,7 +60,7 @@ gulp.task('js:angular', function () { gulp.task('build', gulpsync.sync([ // sync - 'js', + 'js:vanilla', 'js:react', 'js:angular', [ diff --git a/gulp-tasks/webpack.js b/gulp-tasks/webpack.js index 13e81a47..4bc22866 100644 --- a/gulp-tasks/webpack.js +++ b/gulp-tasks/webpack.js @@ -8,12 +8,21 @@ var paths = { src: './src/' }; -var entry = 'react.js'; +gulp.task('js:vanilla', function () { + return gulp.src(path.join(paths.src + 'Cleave.js')) + .pipe(webpack({ + output: { + library: 'Cleave', + libraryTarget: 'umd', + filename: 'cleave.js' + } + })) + .pipe(gulp.dest(paths.dist)); +}); gulp.task('js:react', function () { - return gulp.src(path.join(paths.root, entry)) + return gulp.src(path.join(paths.root, 'react.js')) .pipe(webpack({ - entry: './src/Cleave.react.js', output: { library: 'Cleave', libraryTarget: 'umd', diff --git a/src/Cleave.js b/src/Cleave.js index 3f72cab0..9ce4d181 100644 --- a/src/Cleave.js +++ b/src/Cleave.js @@ -320,14 +320,12 @@ Cleave.prototype = { } }; -if (typeof module === 'object' && typeof module.exports === 'object') { - Cleave.NumeralFormatter = require('./shortcuts/NumeralFormatter'); - Cleave.DateFormatter = require('./shortcuts/DateFormatter'); - Cleave.PhoneFormatter = require('./shortcuts/PhoneFormatter'); - Cleave.CreditCardDetector = require('./shortcuts/CreditCardDetector'); - Cleave.Util = require('./utils/Util'); - Cleave.DefaultProperties = require('./common/DefaultProperties'); - - // CommonJS - module.exports = exports = Cleave; -} +Cleave.NumeralFormatter = require('./shortcuts/NumeralFormatter'); +Cleave.DateFormatter = require('./shortcuts/DateFormatter'); +Cleave.PhoneFormatter = require('./shortcuts/PhoneFormatter'); +Cleave.CreditCardDetector = require('./shortcuts/CreditCardDetector'); +Cleave.Util = require('./utils/Util'); +Cleave.DefaultProperties = require('./common/DefaultProperties'); + +// CommonJS +module.exports = Cleave; diff --git a/src/build/expose.js b/src/build/expose.js deleted file mode 100644 index bd1e240d..00000000 --- a/src/build/expose.js +++ /dev/null @@ -1,21 +0,0 @@ -Cleave.NumeralFormatter = NumeralFormatter; -Cleave.DateFormatter = DateFormatter; -Cleave.PhoneFormatter = PhoneFormatter; -Cleave.CreditCardDetector = CreditCardDetector; -Cleave.Util = Util; -Cleave.DefaultProperties = DefaultProperties; - -if (typeof module === 'object' && typeof module.exports === 'object') { - // CommonJS - module.exports = exports = Cleave; - -} else if (typeof define === 'function' && define.amd) { - // AMD support - define(function () { - return Cleave; - }); - -} else if (typeof window === 'object') { - // Normal way - window.Cleave = Cleave; -} diff --git a/src/build/prefix.js b/src/build/prefix.js deleted file mode 100644 index f149da07..00000000 --- a/src/build/prefix.js +++ /dev/null @@ -1 +0,0 @@ -;(function(window, document, undefined) { diff --git a/src/build/suffix.js b/src/build/suffix.js deleted file mode 100644 index 1292c703..00000000 --- a/src/build/suffix.js +++ /dev/null @@ -1 +0,0 @@ -})(window, document); diff --git a/src/common/DefaultProperties.js b/src/common/DefaultProperties.js index 0dfd0ad1..40e31da8 100644 --- a/src/common/DefaultProperties.js +++ b/src/common/DefaultProperties.js @@ -69,6 +69,5 @@ var DefaultProperties = { } }; -if (typeof module === 'object' && typeof module.exports === 'object') { - module.exports = exports = DefaultProperties; -} +module.exports = DefaultProperties; + diff --git a/src/shortcuts/CreditCardDetector.js b/src/shortcuts/CreditCardDetector.js index 5f730f25..b99f7fac 100644 --- a/src/shortcuts/CreditCardDetector.js +++ b/src/shortcuts/CreditCardDetector.js @@ -122,6 +122,5 @@ var CreditCardDetector = { } }; -if (typeof module === 'object' && typeof module.exports === 'object') { - module.exports = exports = CreditCardDetector; -} +module.exports = CreditCardDetector; + diff --git a/src/shortcuts/DateFormatter.js b/src/shortcuts/DateFormatter.js index 23b4e763..939e32ae 100644 --- a/src/shortcuts/DateFormatter.js +++ b/src/shortcuts/DateFormatter.js @@ -70,6 +70,5 @@ DateFormatter.prototype = { } }; -if (typeof module === 'object' && typeof module.exports === 'object') { - module.exports = exports = DateFormatter; -} +module.exports = DateFormatter; + diff --git a/src/shortcuts/NumeralFormatter.js b/src/shortcuts/NumeralFormatter.js index d2254b91..ea731b43 100644 --- a/src/shortcuts/NumeralFormatter.js +++ b/src/shortcuts/NumeralFormatter.js @@ -78,6 +78,4 @@ NumeralFormatter.prototype = { } }; -if (typeof module === 'object' && typeof module.exports === 'object') { - module.exports = exports = NumeralFormatter; -} +module.exports = NumeralFormatter; diff --git a/src/shortcuts/PhoneFormatter.js b/src/shortcuts/PhoneFormatter.js index 11b509a9..9c4e52f4 100644 --- a/src/shortcuts/PhoneFormatter.js +++ b/src/shortcuts/PhoneFormatter.js @@ -54,6 +54,5 @@ PhoneFormatter.prototype = { } }; -if (typeof module === 'object' && typeof module.exports === 'object') { - module.exports = exports = PhoneFormatter; -} +module.exports = PhoneFormatter; +