From e516af7f993a5797df7c7f7308547cc853b75548 Mon Sep 17 00:00:00 2001 From: Mark Brocato Date: Wed, 11 Mar 2020 00:02:50 +0200 Subject: [PATCH] Fixes and issue with building the service worker. --- package.json | 2 +- plugins/withReactStorefront.js | 122 ++++++++++++++------------------- 2 files changed, 53 insertions(+), 71 deletions(-) diff --git a/package.json b/package.json index 4f5e46fe..eafcfd45 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-storefront", - "version": "7.8.0", + "version": "7.8.1", "description": "Build and deploy e-commerce progressive web apps (PWAs) in record time.", "module": "./index.js", "license": "Apache-2.0", diff --git a/plugins/withReactStorefront.js b/plugins/withReactStorefront.js index 494a6dfe..f4ab83ab 100644 --- a/plugins/withReactStorefront.js +++ b/plugins/withReactStorefront.js @@ -3,85 +3,67 @@ const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPl const API_VERSION = new Date().getTime() const withServiceWorker = require('./withServiceWorker') const ClearRequireCachePlugin = require('webpack-clear-require-cache-plugin') -const chalk = require('chalk') module.exports = (nextConfig = {}) => { const usePreact = process.env.preact === 'true' - return phase => { - const bootstrapOptions = { - prefetchRampUpTime: -5000, - allowPrefetchThrottling: false, - serveSSRFromCache: false, - } + return withServiceWorker({ + ...nextConfig, + target: 'serverless', + webpack(config, options) { + config.resolve.symlinks = false - // if debugging service workers, options can be changed in Dev phase: - if (phase === PHASE_DEVELOPMENT_SERVER) { - bootstrapOptions.allowPrefetchThrottling = true - } + if (usePreact) { + config.resolve.alias = { + ...config.resolve.alias, + react: 'preact/compat', + react$: 'preact/compat', + 'react-dom/test-utils': 'preact/test-utils', + 'react-dom': 'preact/compat', + 'react-dom$': 'preact/compat', + } + } - const { bootstrapPath, makeCopyOptions } = copyBootstrap(bootstrapOptions) + config.plugins.push( + new webpack.DefinePlugin({ + 'process.env.RSF_API_VERSION': JSON.stringify(API_VERSION), + }), + ) - return withServiceWorker( - { - ...nextConfig, - target: 'serverless', - webpack(config, options) { - config.resolve.symlinks = false + if (process.env.NODE_ENV === 'development') { + // This makes it easier to develop apps against a local clone of react-storefront linked with yalc. Here + // we ensure that the server build recompiles when any linked dependency changes. + config.plugins.push( + new ClearRequireCachePlugin([ + /\.next\/server\/ssr-module-cache.js/, + /react-storefront-analytics/, + /react-storefront-amp/, + /react-storefront\//, + ]), + ) + } - if (usePreact) { - config.resolve.alias = { - ...config.resolve.alias, - react: 'preact/compat', - react$: 'preact/compat', - 'react-dom/test-utils': 'preact/test-utils', - 'react-dom': 'preact/compat', - 'react-dom$': 'preact/compat', - } - } + config.module.rules.push({ + test: /\.svg$/, + use: ['@svgr/webpack'], + }) - config.plugins.push( - new webpack.DefinePlugin({ - 'process.env.RSF_API_VERSION': JSON.stringify(API_VERSION), - }), - ) + if (!options.isServer && process.env.analyze === 'true') { + config.plugins.push(new BundleAnalyzerPlugin()) + } - if (process.env.NODE_ENV === 'development') { - // This makes it easier to develop apps against a local clone of react-storefront linked with yalc. Here - // we ensure that the server build recompiles when any linked dependency changes. - config.plugins.push( - new ClearRequireCachePlugin([ - /\.next\/server\/ssr-module-cache.js/, - /react-storefront-analytics/, - /react-storefront-amp/, - /react-storefront\//, - ]), - ) - } + if (typeof nextConfig.webpack === 'function') { + return nextConfig.webpack(config, options) + } - config.module.rules.push({ - test: /\.svg$/, - use: ['@svgr/webpack'], - }) - - if (!options.isServer && process.env.analyze === 'true') { - config.plugins.push(new BundleAnalyzerPlugin()) - } - - if (typeof nextConfig.webpack === 'function') { - return nextConfig.webpack(config, options) - } - - return config - }, - webpackDevMiddleware(config) { - config.watchOptions = { - // required to recompile client build when there are changes in node_modules - ignored: [], - } - return config - }, - }, - ) - } + return config + }, + webpackDevMiddleware(config) { + config.watchOptions = { + // required to recompile client build when there are changes in node_modules + ignored: [], + } + return config + }, + }) }