Skip to content

Commit a815bd5

Browse files
author
Shuwen Qian
committed
Add dan's module exclude stuff
1 parent 148302f commit a815bd5

1 file changed

Lines changed: 53 additions & 16 deletions

File tree

Gulpfile.js

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var minimist = require('minimist');
3939
var serveStatic = require('serve-static');
4040
var connect = require('connect');
4141
var open = require('gulp-open');
42+
var Vulcanize = require('vulcanize');
4243

4344
var SRC = 'src/';
4445
var BUILD = 'build/';
@@ -99,17 +100,52 @@ gulp.task('font', function() {
99100
.pipe(gulp.dest(BUILD + '/shared/fonts/'));
100101
});
101102

103+
function vulcanizeSingle(opts, baseList, basePath) {
104+
opts = opts || {};
105+
106+
return through.obj(function (file, enc, cb) {
107+
if (file.isNull()) {
108+
cb(null, file);
109+
return;
110+
}
111+
112+
if (file.isStream()) {
113+
cb(new gutil.PluginError('gulp-vulcanize', 'Streaming not supported'));
114+
return;
115+
}
116+
117+
var bl = baseList.slice() || [];
118+
var idx = bl.indexOf(basePath + file.relative);
119+
console.log(idx, basePath + file.relative);
120+
bl.splice(idx, 1);
121+
opts.excludes = bl;
122+
console.log(opts.excludes);
123+
124+
(new Vulcanize(opts)).process(file.path, function (err, inlinedHtml) {
125+
if (err) {
126+
cb(new gutil.PluginError('gulp-vulcanize', err, {fileName: file.path}));
127+
return;
128+
}
129+
130+
file.contents = new Buffer(inlinedHtml);
131+
cb(null, file);
132+
}.bind(this));
133+
});
134+
};
135+
102136
gulp.task('vulcanize', function() {
103-
var modules = gulp.src(BUILD + "mm-*/mm-*.html")
104-
// .pipe(changed(BUILD))
105-
.pipe(vulcanize({
106-
inlineScripts: true,
107-
inlineCss: true,
108-
excludes: ['bower_components/polymer/polymer.html']
109-
}))
110-
.pipe(debug())
111-
.pipe(htmlmin())
112-
.pipe(gulp.dest(BUILD));
137+
var excludes = glob.sync(BUILD + 'mm-*/mm-*.html');
138+
excludes.push('bower_components/polymer/polymer.html');
139+
140+
var modules = gulp.src(BUILD + "mm-*/mm-*.html")
141+
// .pipe(changed(BUILD))
142+
.pipe(vulcanizeSingle({
143+
inlineScripts: true,
144+
inlineCss: true
145+
}, excludes, BUILD))
146+
.pipe(debug())
147+
.pipe(htmlmin())
148+
.pipe(gulp.dest(BUILD));
113149

114150
var lib = gulp.src(BUILD + "strand.html")
115151
.pipe(vulcanize({
@@ -130,13 +166,14 @@ gulp.task('build', function(cb) {
130166
});
131167

132168
gulp.task('build:prod', ['patch-lib', 'build'], function() {
169+
var excludes = glob.sync(BUILD + 'mm-*/mm-*.html');
170+
excludes.push('bower_components/polymer/polymer.html');
171+
133172
var modules = gulp.src(BUILD + 'mm-*/mm-*.html')
134-
.pipe(vulcanize({
135-
inlineScripts:true,
136-
inlineCss:true,
137-
stripExcludes:false,
138-
excludes: ['bower_components/polymer/polymer.html']
139-
}))
173+
.pipe(vulcanizeSingle({
174+
inlineScripts: true,
175+
inlineCss: true
176+
}, excludes, BUILD))
140177
.pipe(base64(['.woff']))
141178
.pipe(htmlmin({
142179
quotes: true,

0 commit comments

Comments
 (0)