Skip to content

Commit e516af7

Browse files
committed
Fixes and issue with building the service worker.
1 parent b3f939c commit e516af7

File tree

2 files changed

+53
-71
lines changed

2 files changed

+53
-71
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-storefront",
3-
"version": "7.8.0",
3+
"version": "7.8.1",
44
"description": "Build and deploy e-commerce progressive web apps (PWAs) in record time.",
55
"module": "./index.js",
66
"license": "Apache-2.0",

plugins/withReactStorefront.js

Lines changed: 52 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,85 +3,67 @@ const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPl
33
const API_VERSION = new Date().getTime()
44
const withServiceWorker = require('./withServiceWorker')
55
const ClearRequireCachePlugin = require('webpack-clear-require-cache-plugin')
6-
const chalk = require('chalk')
76

87
module.exports = (nextConfig = {}) => {
98
const usePreact = process.env.preact === 'true'
109

11-
return phase => {
12-
const bootstrapOptions = {
13-
prefetchRampUpTime: -5000,
14-
allowPrefetchThrottling: false,
15-
serveSSRFromCache: false,
16-
}
10+
return withServiceWorker({
11+
...nextConfig,
12+
target: 'serverless',
13+
webpack(config, options) {
14+
config.resolve.symlinks = false
1715

18-
// if debugging service workers, options can be changed in Dev phase:
19-
if (phase === PHASE_DEVELOPMENT_SERVER) {
20-
bootstrapOptions.allowPrefetchThrottling = true
21-
}
16+
if (usePreact) {
17+
config.resolve.alias = {
18+
...config.resolve.alias,
19+
react: 'preact/compat',
20+
react$: 'preact/compat',
21+
'react-dom/test-utils': 'preact/test-utils',
22+
'react-dom': 'preact/compat',
23+
'react-dom$': 'preact/compat',
24+
}
25+
}
2226

23-
const { bootstrapPath, makeCopyOptions } = copyBootstrap(bootstrapOptions)
27+
config.plugins.push(
28+
new webpack.DefinePlugin({
29+
'process.env.RSF_API_VERSION': JSON.stringify(API_VERSION),
30+
}),
31+
)
2432

25-
return withServiceWorker(
26-
{
27-
...nextConfig,
28-
target: 'serverless',
29-
webpack(config, options) {
30-
config.resolve.symlinks = false
33+
if (process.env.NODE_ENV === 'development') {
34+
// This makes it easier to develop apps against a local clone of react-storefront linked with yalc. Here
35+
// we ensure that the server build recompiles when any linked dependency changes.
36+
config.plugins.push(
37+
new ClearRequireCachePlugin([
38+
/\.next\/server\/ssr-module-cache.js/,
39+
/react-storefront-analytics/,
40+
/react-storefront-amp/,
41+
/react-storefront\//,
42+
]),
43+
)
44+
}
3145

32-
if (usePreact) {
33-
config.resolve.alias = {
34-
...config.resolve.alias,
35-
react: 'preact/compat',
36-
react$: 'preact/compat',
37-
'react-dom/test-utils': 'preact/test-utils',
38-
'react-dom': 'preact/compat',
39-
'react-dom$': 'preact/compat',
40-
}
41-
}
46+
config.module.rules.push({
47+
test: /\.svg$/,
48+
use: ['@svgr/webpack'],
49+
})
4250

43-
config.plugins.push(
44-
new webpack.DefinePlugin({
45-
'process.env.RSF_API_VERSION': JSON.stringify(API_VERSION),
46-
}),
47-
)
51+
if (!options.isServer && process.env.analyze === 'true') {
52+
config.plugins.push(new BundleAnalyzerPlugin())
53+
}
4854

49-
if (process.env.NODE_ENV === 'development') {
50-
// This makes it easier to develop apps against a local clone of react-storefront linked with yalc. Here
51-
// we ensure that the server build recompiles when any linked dependency changes.
52-
config.plugins.push(
53-
new ClearRequireCachePlugin([
54-
/\.next\/server\/ssr-module-cache.js/,
55-
/react-storefront-analytics/,
56-
/react-storefront-amp/,
57-
/react-storefront\//,
58-
]),
59-
)
60-
}
55+
if (typeof nextConfig.webpack === 'function') {
56+
return nextConfig.webpack(config, options)
57+
}
6158

62-
config.module.rules.push({
63-
test: /\.svg$/,
64-
use: ['@svgr/webpack'],
65-
})
66-
67-
if (!options.isServer && process.env.analyze === 'true') {
68-
config.plugins.push(new BundleAnalyzerPlugin())
69-
}
70-
71-
if (typeof nextConfig.webpack === 'function') {
72-
return nextConfig.webpack(config, options)
73-
}
74-
75-
return config
76-
},
77-
webpackDevMiddleware(config) {
78-
config.watchOptions = {
79-
// required to recompile client build when there are changes in node_modules
80-
ignored: [],
81-
}
82-
return config
83-
},
84-
},
85-
)
86-
}
59+
return config
60+
},
61+
webpackDevMiddleware(config) {
62+
config.watchOptions = {
63+
// required to recompile client build when there are changes in node_modules
64+
ignored: [],
65+
}
66+
return config
67+
},
68+
})
8769
}

0 commit comments

Comments
 (0)