Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Add --inline option to inline all scripts into main document (opposit…
Browse files Browse the repository at this point in the history
…e of --csp)
  • Loading branch information
dfreedm committed Sep 24, 2013
1 parent d4ed6d4 commit 91b80e8
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion vulcanize/vulcan.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ var options = nopt(
'output': path,
'input': path,
'verbose': Boolean,
'csp': Boolean
'csp': Boolean,
'inline': Boolean
},
{
'o': ['--output'],
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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');
}

Expand Down

0 comments on commit 91b80e8

Please sign in to comment.