From 91b80e8b865d301c20f5376cc66d662b020bc0f8 Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Tue, 24 Sep 2013 10:42:16 -0700 Subject: [PATCH] Add --inline option to inline all scripts into main document (opposite of --csp) --- vulcanize/vulcan.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/vulcanize/vulcan.js b/vulcanize/vulcan.js index 35671ee..f579a6e 100644 --- a/vulcanize/vulcan.js +++ b/vulcanize/vulcan.js @@ -21,7 +21,8 @@ var options = nopt( 'output': path, 'input': path, 'verbose': Boolean, - 'csp': Boolean + 'csp': Boolean, + 'inline': Boolean }, { 'o': ['--output'], @@ -186,6 +187,16 @@ function insertInlinedImports($, storedPosition, importText) { pos[operation](importText); } +function inlineScripts($) { + $('script[src]').each(function() { + var src = this.attr('src'); + if (!ABS_URL.test(src)) { + this.removeAttr('src'); + this.text(fs.readFileSync(src, 'utf8')); + } + }); +} + function handleMainDocument() { var $ = readDocument(options.input); var dir = path.dirname(options.input); @@ -228,6 +239,9 @@ function handleMainDocument() { insertImport($, import_pos, imports_before_polymer.join(EOL) + EOL); insertInlinedImports($, import_pos, output); + if (!options.csp && options.inline) { + inlineScripts($); + } fs.writeFileSync(options.output, $.html(), 'utf8'); }