Skip to content

Commit

Permalink
[demo/gulpfile.js] Issue #61 Add minifyHtmlTemplates option (experime…
Browse files Browse the repository at this point in the history
…ntal and disabled by default)
  • Loading branch information
t2ym committed Feb 20, 2019
1 parent 4979fe3 commit aecddb0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions demo/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const vulcanize = require('gulp-vulcanize');
const debug = require('gulp-debug');
const replace = require('gulp-replace');
const uglify = require('gulp-uglify');
const htmlMinifier = require('html-minifier');
const runSequence = require('run-sequence');
const del = require('del');
const gutil = require('gulp-util');
Expand Down Expand Up @@ -111,6 +112,13 @@ const escodegenOptionsCompact = {
comment: false
};

const minifyHtmlTemplates = false;
const htmlMinifierOptions = {
// Same options as polymer build minify: true
collapseWhitespace: true,
removeComments: true,
};

function UncamelCase (name) {
return name
// insert a hyphen between lower & upper
Expand Down Expand Up @@ -239,6 +247,12 @@ function traverseAst(ast, templates) {
let localizableTextJSON = preprocessedTemplate.substring(indexOfLocalizableText + localizableTextPrefix.length, indexOfLocalizableTextPostfix);
localizableTextJSON = JSON.stringify(JSON.parse(localizableTextJSON), ((key, value) => typeof value === 'string' ? he.decode(value) : value), 2)
let strippedTemplate = preprocessedTemplate.substring(0, indexOfLocalizableText);
if (minifyHtmlTemplates) {
//console.log(`${name}: original ${strippedTemplate}`);
strippedTemplate = htmlMinifier.minify(strippedTemplate, htmlMinifierOptions);
//console.log(`${name}: minified ${strippedTemplate}`);
}

let strings = [{
"type": "Literal",
"value": "<!-- localizable -->",
Expand Down

0 comments on commit aecddb0

Please sign in to comment.