Skip to content

Commit

Permalink
Server ChunkExtractor .getScriptUrls method
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Jun 13, 2019
1 parent e53e9f3 commit 4ed6bc3
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,27 @@ export class ChunkExtractor {
}

getScriptTags(options = {}) {
const scripts = [];
// Create scripts for files
const modifiers = `${options.async ? ' async' : ''}${options.defer ? ' defer' : ''}`;

const urls = this.getScriptUrls();
const scripts = urls.map(url => `<script src="${url}"${modifiers}></script>`);

// Create script for list of lazy chunks to await
const chunkNames = this._chunkNames;
if (chunkNames.length > 0) {
scripts.push(`<script>window.${CLIENT_REQUIRED} = ${JSON.stringify(chunkNames)};</script>`);
}

// Create scripts for files
const modifiers = `${options.async ? ' async' : ''}${options.defer ? ' defer' : ''}`,
publicPath = this._publicPath;
for (const path of this._files) {
scripts.push(`<script src="${publicPath}${path}"${modifiers}></script>`);
scripts.unshift(`<script>window.${CLIENT_REQUIRED} = ${JSON.stringify(chunkNames)};</script>`);
}

return scripts.join('\n');
}

getScriptUrls() {
// Create scripts for files
const publicPath = this._publicPath;
return Array.from(this._files).map(path => `${publicPath}${path}`);
}

_mounted(chunkName, willDisplay) {
// Ignore chunks which won't be displayed
if (!willDisplay) return;
Expand Down

0 comments on commit 4ed6bc3

Please sign in to comment.