From 9239a56958593ac701e212f90e3836b27ba6aa5d Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 19 Jul 2016 02:27:46 -0700 Subject: [PATCH] Use hydrolysis for optimal panel built size --- package.json | 1 + script/vulcanize.js | 20 +++++++++++++------- src/home-assistant.html | 3 ++- src/layouts/partial-base.html | 16 +++++----------- src/resources/panel-imports.html | 10 ---------- 5 files changed, 21 insertions(+), 29 deletions(-) delete mode 100644 src/resources/panel-imports.html diff --git a/package.json b/package.json index da4e0db338..b45a199a0b 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "eslint-plugin-html": "^1.5.1", "eslint-plugin-import": "^1.11.0", "html-minifier": "^3.0.1", + "hydrolysis": "^1.24.1", "polymer-cli": "^0.12.0", "rollup": "^0.34.1", "rollup-plugin-babel": "^2.6.1", diff --git a/script/vulcanize.js b/script/vulcanize.js index 9328f55691..007e3c25ca 100755 --- a/script/vulcanize.js +++ b/script/vulcanize.js @@ -2,6 +2,7 @@ var Vulcanize = require('vulcanize'); var minify = require('html-minifier'); +var hyd = require('hydrolysis'); var fs = require('fs'); if (!fs.existsSync('build')) { @@ -32,14 +33,12 @@ const baseVulcanOptions = { stripComments: true, }; -const vulcan = new Vulcanize({ +const panelVulcan = new Vulcanize({ inlineScripts: true, inlineCss: true, implicitStrip: true, stripComments: true, - stripExcludes: [ - 'bower_components/polymer/polymer.html', - ], + stripExcludes: undefined, }); const toProcess = [ @@ -58,13 +57,13 @@ fs.readdirSync('./panels').forEach(panel => { toProcess.push({ source: `panels/${panel}/ha-panel-${panel}.html`, output: `panels/ha-panel-${panel}.html`, + vulcan: panelVulcan, }); }); function process(entry) { console.log('Processing', entry.source); - const vulc = entry.vulcan || vulcan; - vulc.process(entry.source, (err, inlinedHtml) => { + entry.vulcan.process(entry.source, (err, inlinedHtml) => { if (err !== null) { console.error(entry.source, err); return; @@ -80,4 +79,11 @@ function process(entry) { }); } -process(toProcess.pop()); +// Fetch all dependencies of main app and exclude them from panels +hyd.Analyzer.analyze('src/home-assistant.html') + .then(function (analyzer) { + return analyzer._getDependencies('src/home-assistant.html'); + }) + .then(deps => { panelVulcan.stripExcludes = deps; }) + // And then start vulcanizing!! + .then(() => process(toProcess.pop())); diff --git a/src/home-assistant.html b/src/home-assistant.html index a7d6621897..0ead4d02ac 100644 --- a/src/home-assistant.html +++ b/src/home-assistant.html @@ -12,7 +12,8 @@ - + +