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

Commit 91b80e8

Browse files
committed
Add --inline option to inline all scripts into main document (opposite of --csp)
1 parent d4ed6d4 commit 91b80e8

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

vulcanize/vulcan.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ var options = nopt(
2121
'output': path,
2222
'input': path,
2323
'verbose': Boolean,
24-
'csp': Boolean
24+
'csp': Boolean,
25+
'inline': Boolean
2526
},
2627
{
2728
'o': ['--output'],
@@ -186,6 +187,16 @@ function insertInlinedImports($, storedPosition, importText) {
186187
pos[operation](importText);
187188
}
188189

190+
function inlineScripts($) {
191+
$('script[src]').each(function() {
192+
var src = this.attr('src');
193+
if (!ABS_URL.test(src)) {
194+
this.removeAttr('src');
195+
this.text(fs.readFileSync(src, 'utf8'));
196+
}
197+
});
198+
}
199+
189200
function handleMainDocument() {
190201
var $ = readDocument(options.input);
191202
var dir = path.dirname(options.input);
@@ -228,6 +239,9 @@ function handleMainDocument() {
228239

229240
insertImport($, import_pos, imports_before_polymer.join(EOL) + EOL);
230241
insertInlinedImports($, import_pos, output);
242+
if (!options.csp && options.inline) {
243+
inlineScripts($);
244+
}
231245
fs.writeFileSync(options.output, $.html(), 'utf8');
232246
}
233247

0 commit comments

Comments
 (0)