Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit b9b4add

Browse files
ajoslinrobertmesserle
authored andcommitted
chore(build-all-modules): separate min and non-min streams
1 parent c13b55a commit b9b4add

File tree

2 files changed

+46
-41
lines changed

2 files changed

+46
-41
lines changed

gulpfile.js

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,20 @@ gulp.task('build', ['build-themes', 'build-scss', 'build-js']);
181181

182182

183183
gulp.task('build-all-modules', function() {
184-
var addedCore = false;
185184
return gulp.src(['src/components/*', 'src/core/',])
186185
.pipe(through2.obj(function(folder, enc, next) {
187186
var moduleId = folder.path.indexOf('components') > -1 ?
188187
'material.components.' + path.basename(folder.path) :
189188
'material.' + path.basename(folder.path);
190-
buildModule(moduleId).on('end', function() {
189+
190+
var stream;
191+
if (IS_RELEASE_BUILD) {
192+
stream = mergeStream(buildModule(moduleId, true), buildModule(moduleId, false));
193+
} else {
194+
stream = buildModule(moduleId, false);
195+
}
196+
197+
stream.on('end', function() {
191198
next();
192199
});
193200
}));
@@ -292,16 +299,25 @@ gulp.task('build-js-release', function() {
292299
* @return {function(): Stream}
293300
*/
294301
function minifyJs(fileName) {
295-
// Return a function instead of the stream itself in order to work with
296-
// lazypipe.
297-
return closureCompiler({
298-
compilerPath: 'bower_components/closure-compiler/lib/vendor/compiler.jar',
299-
fileName: fileName,
300-
compilerFlags: {
301-
language_in: 'ECMASCRIPT5',
302-
warning_level: 'QUIET'
303-
}
304-
});
302+
// Figure out filename if not provided
303+
if (!fileName) {
304+
return through2.obj(function(file, enc, next) {
305+
closure(path.basename(file.path)).on('data', this.push.bind(this));
306+
next();
307+
});
308+
} else {
309+
return closure(fileName);
310+
}
311+
function closure(fileName) {
312+
return closureCompiler({
313+
compilerPath: 'bower_components/closure-compiler/lib/vendor/compiler.jar',
314+
fileName: fileName,
315+
compilerFlags: {
316+
language_in: 'ECMASCRIPT5',
317+
warning_level: 'QUIET'
318+
}
319+
});
320+
}
305321
}
306322

307323

@@ -353,37 +369,33 @@ function buildTheme(theme) {
353369

354370

355371
gulp.task('build-module', ['build-demo'], function() {
356-
return buildModule(readModuleArg());
372+
return buildModule(readModuleArg(), IS_RELEASE_BUILD);
357373
});
358374

359-
function buildModule(module) {
375+
function buildModule(module, isRelease) {
360376
var name = module.split('.').pop();
361-
gutil.log('Building module', module, '...');
377+
gutil.log('Building module', module, isRelease && 'minified' || '', '...');
362378
return utils.filesForModule(module)
363379
.pipe(filterNonCodeFiles())
364380
.pipe(gulpif('*.scss', buildModuleStyles(name)))
365381
.pipe(gulpif('*.js', buildModuleJs(name)))
366382
.pipe(BUILD_MODE.transform())
367383
.pipe(insert.prepend(config.banner))
368-
.pipe(gulp.dest(BUILD_MODE.outputDir + name))
369-
.pipe(gulpif(IS_RELEASE_BUILD, lazypipe()
370-
.pipe(gulpif, BUILD_MODE.useBower, lazypipe()
371-
.pipe(gulpif, /.css$/, minifyCss(), through2.obj(function(file, enc, next) {
372-
var name = path.basename(file.path);
373-
minifyJs(name).on('data', this.push.bind(this));
374-
next();
375-
}))
376-
.pipe(rename, function(path) {
377-
path.extname = path.extname
378-
.replace(/.js$/, '.min.js')
379-
.replace(/.css$/, '.min.css');
380-
})
381-
.pipe(utils.buildModuleBower, name, VERSION)
382-
()
383-
)
384+
.pipe(gulpif(isRelease && BUILD_MODE.useBower, buildMin()))
385+
.pipe(gulp.dest(BUILD_MODE.outputDir + name));
386+
387+
function buildMin() {
388+
return lazypipe()
389+
.pipe(gulpif, /.css$/, minifyCss(), minifyJs())
390+
.pipe(rename, function(path) {
391+
path.extname = path.extname
392+
.replace(/.js$/, '.min.js')
393+
.replace(/.css$/, '.min.css');
394+
})
395+
.pipe(utils.buildModuleBower, name, VERSION)
384396
.pipe(gulp.dest, BUILD_MODE.outputDir + name)
385-
()
386-
));
397+
();
398+
}
387399
}
388400

389401

@@ -393,7 +405,7 @@ gulp.task('build-demo', function() {
393405
var demoIndexTemplate = fs.readFileSync(
394406
__dirname + '/docs/demos/demo-index.template.html', 'utf8'
395407
).toString();
396-
408+
397409
gutil.log('Building demos for', mod, '...');
398410
return utils.readModuleDemos(mod, function() {
399411
return lazypipe()

package.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"url": "git://github.com/angular/material.git"
66
},
77
"devDependencies": {
8-
"batch": "^0.5.1",
98
"canonical-path": "0.0.2",
109
"conventional-changelog": "0.0.9",
1110
"dgeni": "^0.4.1",
@@ -18,21 +17,15 @@
1817
"gulp-closure-compiler": "^0.2.7",
1918
"gulp-concat": "^2.2.0",
2019
"gulp-filter": "^1.0.2",
21-
"gulp-footer": "^1.0.4",
22-
"gulp-header": "^1.0.2",
2320
"gulp-if": "^1.2.0",
2421
"gulp-insert": "^0.4.0",
2522
"gulp-jshint": "^1.5.5",
2623
"gulp-minify-css": "^0.3.4",
27-
"gulp-minify-html": "^0.1.6",
2824
"gulp-ng-annotate": "^0.3.5",
2925
"gulp-ng-html2js": "^0.1.8",
3026
"gulp-rename": "^1.2.0",
31-
"gulp-replace": "^0.3.0",
3227
"gulp-sass": "ajoslin/gulp-sass#master",
33-
"gulp-strip-debug": "^0.3.0",
3428
"gulp-uglify": "^0.3.0",
35-
"gulp-uncss": "^0.4.5",
3629
"gulp-util": "^3.0.1",
3730
"gulp-webserver": "^0.8.3",
3831
"jshint-summary": "^0.3.0",

0 commit comments

Comments
 (0)