add preload header for main.js and current route - fixes #2

This commit is contained in:
Rich Harris
2017-12-20 18:04:11 -05:00
parent 8d40992cf1
commit 492f024d2a
2 changed files with 14 additions and 5 deletions

View File

@@ -5,10 +5,12 @@ const templates = require('../templates.js');
const route_manager = require('../route_manager.js');
const { dest } = require('../config.js');
function ensure_array(thing) {
return Array.isArray(thing) ? thing : [thing]; // omg webpack what the HELL are you doing
}
module.exports = function generate_asset_cache(clientInfo, serverInfo) {
let main_file = Array.isArray(clientInfo.assetsByChunkName.main) ?
`/client/${clientInfo.assetsByChunkName.main[0]}` : // omg webpack what the HELL are you doing
`/client/${clientInfo.assetsByChunkName.main}`;
const main_file = `/client/${ensure_array(clientInfo.assetsByChunkName.main)[0]}`;
const chunk_files = clientInfo.assets.map(chunk => `/client/${chunk.name}`);
@@ -29,6 +31,11 @@ module.exports = function generate_asset_cache(clientInfo, serverInfo) {
return lookup;
}, {}),
routes: route_manager.routes.reduce((lookup, route) => {
lookup[route.id] = `/client/${ensure_array(clientInfo.assetsByChunkName[route.id])[0]}`;
return lookup;
}, {}),
index,
service_worker
},