I'm struggling to get a working custom build for Polymer using gulp. My goal is to get a Polymer 1 project written in es6 transpiled & bundled. I followed this guide https://github.com/PolymerElements/generator-polymer-init-custom-build.
The transpilation works well for single files, but any bundled js code is untranspiled (as written in es6). Here is my gulp task :
function build() {
return new Promise((resolve, reject) => { // eslint-disable-line no-unused-vars
// Okay, so first thing we do is clear the build directory
console.log(`Deleting ${buildDirectory} directory...`);
del([buildDirectory])
.then(() => {
// Okay, now let's get your source files
let sourcesStream = polymerProject.sources()
// Here's how splitHtml & gulpif work
.pipe(polymerProject.splitHtml())
// Transpile
.pipe($.sourcemaps.init())
.pipe($.if('*.js', $.babel({
presets: ['es2015']
})))
.pipe($.sourcemaps.write())
// Oh, well do you want to minify stuff? Go for it!
.pipe(gulpif(/\.js$/, uglify()))
.pipe(gulpif(/\.html$/, htmlMinifier()))
.pipe(gulpif(/\.(png|gif|jpg|svg)$/, imagemin()))
.pipe(polymerProject.rejoinHtml());
// Okay, now let's do the same to your dependencies
let dependenciesStream = polymerProject.dependencies()
// .pipe(polymerProject.bundler)
.pipe(polymerProject.splitHtml())
.pipe(gulpif(/\.js$/, uglify()))
.pipe(gulpif(/\.html$/, htmlMinifier()))
.pipe(polymerProject.rejoinHtml());
// Okay, now let's merge them into a single build stream
let buildStream = mergeStream(sourcesStream, dependenciesStream)
.once('data', () => {
console.log('Analyzing build dependencies...');
});
// #PROBLEM# -> All included sources won't be transpiled
buildStream = buildStream.pipe(polymerProject.bundler);
// Okay, time to pipe to the build directory
buildStream = buildStream.pipe(gulp.dest(buildDirectory));
// waitFor the buildStream to complete
return waitFor(buildStream);
})
.then(() => {
// Okay, now let's generate the Service Worker
console.log('Generating the Service Worker...');
return polymerBuild.addServiceWorker({
project: polymerProject,
buildRoot: buildDirectory,
bundled: true,
swPrecacheConfig: swPrecacheConfig
});
})
.then(() => {
// You did it!
console.log('Build complete!');
resolve();
});
});
}
gulp.task('build', build);
Thank you for your help.