From 17092d661ba093dea92fc1cdd20910f2326237a8 Mon Sep 17 00:00:00 2001 From: Fabrizio Fortunato Date: Mon, 19 Jun 2017 22:00:47 +0100 Subject: [PATCH 1/2] feat(umd): uglify the umd bundle --- generators/app/templates/_package.json | 1 + generators/app/templates/gulpfile.js | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/generators/app/templates/_package.json b/generators/app/templates/_package.json index be89dfb..6845029 100644 --- a/generators/app/templates/_package.json +++ b/generators/app/templates/_package.json @@ -55,6 +55,7 @@ "node-watch": "^0.5.2", "protractor": "~5.1.0", "rollup": "^0.41.6", + "rollup-plugin-uglify": "^2.0.1", "run-sequence": "^1.2.2", "rxjs": "^5.1.0", "ts-node": "~2.0.0", diff --git a/generators/app/templates/gulpfile.js b/generators/app/templates/gulpfile.js index 770f1ec..6f60b43 100644 --- a/generators/app/templates/gulpfile.js +++ b/generators/app/templates/gulpfile.js @@ -6,7 +6,8 @@ var gulp = require('gulp'), rename = require('gulp-rename'), del = require('del'), runSequence = require('run-sequence'), - inlineResources = require('./tools/gulp/inline-resources'); + inlineResources = require('./tools/gulp/inline-resources'), + uglify = require('rollup-plugin-uglify'); const rootFolder = path.join(__dirname); const srcFolder = path.join(rootFolder, 'src'); @@ -136,8 +137,14 @@ gulp.task('rollup:umd', function () { // See https://github.com/rollup/rollup/wiki/JavaScript-API#globals globals: { typescript: 'ts' - } - + }, + + // https://github.com/TrySound/rollup-plugin-uglify to uglify the .umd + // For all the options you can have a look at + // https://github.com/mishoo/UglifyJS2#api-reference + plugins: [ + uglify() + ] })) .pipe(rename('<%= props.libraryName.kebabCase %>.umd.js')) .pipe(gulp.dest(distFolder)); From 8d4063876892490a979b29778227162ada4c4f55 Mon Sep 17 00:00:00 2001 From: Fabrizio Fortunato Date: Thu, 29 Jun 2017 20:15:05 +0100 Subject: [PATCH 2/2] feat(umd): build will now generate two umd bundles one *.umd.js and a *.umd.min.js as per comments --- generators/app/templates/_package.json | 3 ++- generators/app/templates/gulpfile.js | 24 ++++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/generators/app/templates/_package.json b/generators/app/templates/_package.json index 6845029..a3015b0 100644 --- a/generators/app/templates/_package.json +++ b/generators/app/templates/_package.json @@ -42,6 +42,7 @@ "gulp": "^3.9.1", "gulp-rename": "^1.2.2", "gulp-rollup": "^2.11.0", + "gulp-uglify": "^3.0.0", "jasmine-core": "~2.5.2", "jasmine-spec-reporter": "~3.2.0", "karma": "~1.4.1", @@ -54,8 +55,8 @@ "node-sass-tilde-importer": "^1.0.0", "node-watch": "^0.5.2", "protractor": "~5.1.0", + "pump": "^1.0.2", "rollup": "^0.41.6", - "rollup-plugin-uglify": "^2.0.1", "run-sequence": "^1.2.2", "rxjs": "^5.1.0", "ts-node": "~2.0.0", diff --git a/generators/app/templates/gulpfile.js b/generators/app/templates/gulpfile.js index 6f60b43..e8e11af 100644 --- a/generators/app/templates/gulpfile.js +++ b/generators/app/templates/gulpfile.js @@ -3,11 +3,12 @@ var gulp = require('gulp'), path = require('path'), ngc = require('@angular/compiler-cli/src/main').main, rollup = require('gulp-rollup'), + uglify = require('gulp-uglify'), + pump = require('pump'), rename = require('gulp-rename'), del = require('del'), runSequence = require('run-sequence'), - inlineResources = require('./tools/gulp/inline-resources'), - uglify = require('rollup-plugin-uglify'); + inlineResources = require('./tools/gulp/inline-resources'); const rootFolder = path.join(__dirname); const srcFolder = path.join(rootFolder, 'src'); @@ -137,19 +138,21 @@ gulp.task('rollup:umd', function () { // See https://github.com/rollup/rollup/wiki/JavaScript-API#globals globals: { typescript: 'ts' - }, - - // https://github.com/TrySound/rollup-plugin-uglify to uglify the .umd - // For all the options you can have a look at - // https://github.com/mishoo/UglifyJS2#api-reference - plugins: [ - uglify() - ] + } })) .pipe(rename('<%= props.libraryName.kebabCase %>.umd.js')) .pipe(gulp.dest(distFolder)); }); +gulp.task('uglify', function (cb) { + pump([ + gulp.src(`${distFolder}/<%= props.libraryName.kebabCase %>.umd.js`), + uglify(), + rename('<%= props.libraryName.kebabCase %>.umd.min.js'), + gulp.dest(distFolder) + ], cb); +}); + /** * 7. Copy all the files from /build to /dist, except .js files. We ignore all .js from /build * because with don't need individual modules anymore, just the Flat ES module generated @@ -198,6 +201,7 @@ gulp.task('compile', function () { 'ngc', 'rollup:fesm', 'rollup:umd', + 'uglify', 'copy:build', 'copy:manifest', 'copy:readme',