Skip to content

Commit

Permalink
implement importScripts option for SWPrecacheWebpackPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-cz committed Jul 3, 2017
1 parent df00d80 commit c566e73
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/react-scripts/config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/react-scripts/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit c566e73

Please sign in to comment.