Skip to content

Commit

Permalink
Service worker fixes for oss archetype app (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
didi0613 authored and jchip committed May 2, 2017
1 parent 410c657 commit cbb0c01
Showing 1 changed file with 21 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,16 @@ function createEntryConfigFromScripts(importScripts, entry) {
// entry points. If it is we create a new object with all
// existing entry points to avoid mutating the config. If its not,
// we assume its a string and use it as the main entry point.
const newEntry = typeof entry === "object"
? Object.assign({}, entry)
: { main: entry };
const newEntry = typeof entry === "object" ?
Object.assign({}, entry) : { main: entry };
return importScripts.reduce((acc, script) => {
const name = Path.parse(script).name;
acc[name] = script;
return acc;
}, newEntry);
}

module.exports = function (options) {
module.exports = function(options) {
/* eslint max-statements: 0 */
const swConfig = optionalRequire(swConfigPath, true) || {};
const severConfig = optionalRequire(serverConfigPath, true) || {};
Expand Down Expand Up @@ -116,15 +115,16 @@ module.exports = function (options) {
* the entry config and output config so we get an entry point for each
* script with unique names.
*/
let entry = {};
let output = {};
if (cacheConfig.importScripts) {
const importScripts = cacheConfig.importScripts;

cacheConfig.importScripts = process.env.WEBPACK_DEV === "true"
? importScripts.map(getDevelopmentPath)
: importScripts.map(getHashedPath);
cacheConfig.importScripts = process.env.WEBPACK_DEV === "true" ?
importScripts.map(getDevelopmentPath) :
importScripts.map(getHashedPath);

createEntryConfigFromScripts(importScripts, options.currentConfig.entry);
entry = createEntryConfigFromScripts(importScripts, options.currentConfig.entry);

output = {
filename: "[name].[hash].js"
Expand Down Expand Up @@ -178,23 +178,21 @@ module.exports = function (options) {
}

return {
entry,
output,
module: {
rules: [
{
_name: "manifest",
test: /manifest.json$/,
use: [
{
loader: fileLoader,
options: {
name: "manifest.json"
}
},
webAppManifestLoader
]
}
]
rules: [{
_name: "manifest",
test: /manifest.json$/,
use: [{
loader: fileLoader,
options: {
name: "manifest.json"
}
},
webAppManifestLoader
]
}]
},
plugins
};
Expand Down

0 comments on commit cbb0c01

Please sign in to comment.