| 9 | const { paths } = require('./gulp-config'); |
| 10 | |
| 11 | function buildPolymer(project, develop) { |
| 12 | const sources = project.sources() |
| 13 | .pipe($.if(['index.html', 'app.html'], $.useref())) |
| 14 | .pipe($.if('elements/app-shell.html', $.template({ |
| 15 | ENV: process.env |
| 16 | }))); |
| 17 | const stream = mergeStream(sources, project.dependencies()); |
| 18 | |
| 19 | if (develop) { |
| 20 | return stream.pipe(project.bundler()); |
| 21 | } |
| 22 | |
| 23 | const htmlSplitter = new HtmlSplitter(); |
| 24 | return stream |
| 25 | .pipe(htmlSplitter.split()) |
| 26 | .pipe($.if(/\.html$/, $.htmlPostcss({ |
| 27 | plugins: [autoprefixer({ browsenrs: ['last 2 versions'] })] |
| 28 | }))) |
| 29 | .pipe($.if( |
| 30 | file => path.extname(file.path) === '.js' && |
| 31 | file.path.indexOf('webcomponentsjs') === -1 && |
| 32 | file.path.indexOf('firebase') === -1, |
| 33 | $.babel() |
| 34 | )) |
| 35 | .pipe($.if( |
| 36 | file => path.extname(file.path) === '.js' && |
| 37 | file.path.indexOf('webcomponentsjs') === -1 && |
| 38 | file.path.indexOf('firebase') === -1, |
| 39 | $.babili() |
| 40 | )) |
| 41 | .pipe(htmlSplitter.rejoin()) |
| 42 | .pipe($.if(/\.html$/, $.htmlmin({ |
| 43 | collapseWhitespace: true, |
| 44 | removeComments: true |
| 45 | }))) |
| 46 | .pipe(project.addCustomElementsEs5Adapter()) |
| 47 | .pipe(project.bundler()) |
| 48 | .pipe(project.addPushManifest()); |
| 49 | } |
| 50 | |
| 51 | gulp.task('polymer', ['prepare-env'], function () { |
| 52 | const project = new PolymerProject(require('../polymer.json')); |