From c566e734f2e36c952b9239e5b8af5623c2e66859 Mon Sep 17 00:00:00 2001 From: Piotr Konieczny Date: Mon, 3 Jul 2017 12:22:23 +0200 Subject: [PATCH] implement importScripts option for SWPrecacheWebpackPlugin --- packages/react-scripts/config/paths.js | 6 ++++++ packages/react-scripts/config/webpack.config.prod.js | 1 + 2 files changed, 7 insertions(+) diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index 94e399f0f4..3cf088c785 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -48,6 +48,10 @@ function getServedPath(appPackageJson) { return ensureSlash(servedUrl, true); } +const sWPrecacheImportScript = fs.existsSync(resolveApp('public/service-worker-import.js')) + ? 'service-worker-import.js' + : undefined; + // config after eject: we're in ./config/ module.exports = { dotenv: resolveApp('.env'), @@ -62,6 +66,7 @@ module.exports = { appNodeModules: resolveApp('node_modules'), publicUrl: getPublicUrl(resolveApp('package.json')), servedPath: getServedPath(resolveApp('package.json')), + sWPrecacheImportScript: sWPrecacheImportScript, }; // @remove-on-eject-begin @@ -82,6 +87,7 @@ module.exports = { appNodeModules: resolveApp('node_modules'), publicUrl: getPublicUrl(resolveApp('package.json')), servedPath: getServedPath(resolveApp('package.json')), + sWPrecacheImportScript: sWPrecacheImportScript, // These properties only exist before ejecting: ownPath: resolveOwn('.'), ownNodeModules: resolveOwn('node_modules'), // This is empty on npm 3 diff --git a/packages/react-scripts/config/webpack.config.prod.js b/packages/react-scripts/config/webpack.config.prod.js index 1ba1307bb3..ce88a987ea 100644 --- a/packages/react-scripts/config/webpack.config.prod.js +++ b/packages/react-scripts/config/webpack.config.prod.js @@ -322,6 +322,7 @@ module.exports = { // about it being stale, and the cache-busting can be skipped. dontCacheBustUrlsMatching: /\.\w{8}\./, filename: 'service-worker.js', + importScripts: paths.sWPrecacheImportScript ? [paths.sWPrecacheImportScript] : undefined, logger(message) { if (message.indexOf('Total precache size is') === 0) { // This message occurs for every build and is a bit too noisy.