Skip to content

Commit

Permalink
Add better minification
Browse files Browse the repository at this point in the history
  • Loading branch information
ozasadnyy committed May 29, 2017
1 parent 36d9030 commit 4552e74
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ addons:
- g++-4.8
install:
- npm install -g bower
- npm install
- bower install
- npm install
script: echo "Deploying!"
before_deploy: npm run build
deploy:
Expand Down
26 changes: 18 additions & 8 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@
const del = require('del');
const gulp = require('gulp');
const gulpif = require('gulp-if');
const uglify = require('gulp-uglify');
const uglifyes = require('uglify-es');
const composer = require('gulp-uglify/composer');
const cssSlam = require('css-slam').gulp;
const mergeStream = require('merge-stream');
const polymerBuild = require('polymer-build');
const HtmlSplitter = require('polymer-build').HtmlSplitter;
const browserSync = require('browser-sync').create();
const history = require('connect-history-api-fallback');

const HtmlSplitter = polymerBuild.HtmlSplitter;
const PolymerProject = polymerBuild.PolymerProject;
const uglify = composer(uglifyes, console);

const logging = require('plylog');
// logging.setVerbose();

const config = {
polymerJsonPath: './polymer.json',
build: {
rootDirectory: 'build',
bundled: true
rootDirectory: 'build'
},
swPrecacheConfigPath: './sw-precache-config.js',
templateData: [
Expand Down Expand Up @@ -54,7 +57,7 @@ function build() {

const compileStream = template.compile(config, polymerJson)
.on('end', () => {
polymerProject = new polymerBuild.PolymerProject(buildPolymerJson);
polymerProject = new PolymerProject(buildPolymerJson);
});
return waitFor(compileStream);
})
Expand All @@ -65,7 +68,7 @@ function build() {
const sourcesStream = polymerProject.sources()
.pipe(sourcesHtmlSplitter.split())
// splitHtml doesn't split CSS https://github.com/Polymer/polymer-build/issues/32
// .pipe(gulpif(/\.js$/, uglify()))
.pipe(gulpif(/\.js$/, uglify()))
.pipe(gulpif(/\.(html|css)$/, cssSlam()))
.pipe(gulpif(/\.html$/, html.minify()))
.pipe(gulpif(/\.(png|gif|jpg|svg)$/, images.minify()))
Expand All @@ -75,7 +78,7 @@ function build() {
const dependenciesStream = polymerProject.dependencies()
.pipe(dependenciesHtmlSplitter.split())
// Doesn't work for now
// .pipe(gulpif(/\.js$/, uglify()))
.pipe(gulpif(/\.js$/, uglify()))
.pipe(gulpif(/\.(html|css)$/, cssSlam()))
.pipe(gulpif(/\.html$/, html.minify()))
.pipe(dependenciesHtmlSplitter.rejoin());
Expand All @@ -85,7 +88,9 @@ function build() {
console.log('Analyzing and optimizing...');
});

buildStream = buildStream.pipe(polymerProject.bundler());
buildStream = buildStream.pipe(polymerProject.bundler({
stripComments: true
}));
buildStream = buildStream.pipe(gulp.dest(config.build.rootDirectory));
return waitFor(buildStream);
})
Expand All @@ -109,6 +114,11 @@ function build() {

return waitFor(normalizeStream);
})
.then(() => {
return gulp.src(prependPath(config.build.rootDirectory, 'service-worker.js'))
.pipe(uglify())
.pipe(gulp.dest(config.build.rootDirectory));
})
.then(() => {
console.log('Build complete!');
resolve();
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"plylog": "^0.5.0",
"polymer-build": "^1.5.0",
"require-uncached": "^1.0.0",
"sw-precache": "^5.0.0"
"sw-precache": "^5.0.0",
"uglify-es": "^3.0.13"
},
"engines": {
"node": ">=4.0"
Expand Down

0 comments on commit 4552e74

Please sign in to comment.