@@ -3,85 +3,67 @@ const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPl
33const API_VERSION = new Date ( ) . getTime ( )
44const withServiceWorker = require ( './withServiceWorker' )
55const ClearRequireCachePlugin = require ( 'webpack-clear-require-cache-plugin' )
6- const chalk = require ( 'chalk' )
76
87module . 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+ / \. n e x t \/ s e r v e r \/ s s r - m o d u l e - c a c h e .j s / ,
39+ / r e a c t - s t o r e f r o n t - a n a l y t i c s / ,
40+ / r e a c t - s t o r e f r o n t - a m p / ,
41+ / r e a c t - s t o r e f r o n t \/ / ,
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 : / \. s v g $ / ,
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- / \. n e x t \/ s e r v e r \/ s s r - m o d u l e - c a c h e .j s / ,
55- / r e a c t - s t o r e f r o n t - a n a l y t i c s / ,
56- / r e a c t - s t o r e f r o n t - a m p / ,
57- / r e a c t - s t o r e f r o n t \/ / ,
58- ] ) ,
59- )
60- }
55+ if ( typeof nextConfig . webpack === 'function' ) {
56+ return nextConfig . webpack ( config , options )
57+ }
6158
62- config . module . rules . push ( {
63- test : / \. s v g $ / ,
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