Skip to content

Commit

Permalink
Fixes and issue with building the service worker.
Browse files Browse the repository at this point in the history
  • Loading branch information
markbrocato committed Mar 10, 2020
1 parent b3f939c commit e516af7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 71 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
122 changes: 52 additions & 70 deletions plugins/withReactStorefront.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
})
}

0 comments on commit e516af7

Please sign in to comment.