@@ -5,6 +5,13 @@ const withCSS = require('@zeit/next-css')
55const withLess = require ( '@zeit/next-less' )
66const withSass = require ( '@zeit/next-sass' )
77const withPWA = require ( 'next-pwa' )
8+ const withOptimizedImages = require ( 'next-optimized-images' )
9+
10+ const isProdBuild = process . env . NODE_ENV === 'production'
11+
12+ const baseNextConfig = {
13+ target : 'serverless' ,
14+ }
815
916const lessNextConfig = {
1017 lessLoaderOptions : {
@@ -41,15 +48,24 @@ const sassNextConfig = {
4148 cssModules : true ,
4249}
4350
51+ const optimizedImagesNextConfig = {
52+ /**
53+ * Auto-detects:
54+ * - imagemin-mozjpeg
55+ * - imagemin-optipng
56+ * - webp-loader
57+ */
58+ }
59+
4460const pwaNextConfig = {
4561 pwa : {
4662 dest : 'public' ,
47- disable : process . env . NODE_ENV === 'development' ,
63+ disable : ! isProdBuild ,
4864 } ,
4965}
5066
5167const compose = ( plugins ) => ( {
52- target : 'serverless' ,
68+ ... baseNextConfig ,
5369
5470 webpack : ( config , options ) => {
5571 config . module . rules . push (
@@ -77,6 +93,7 @@ const compose = (plugins) => ({
7793 return config
7894 } , config )
7995 } ,
96+
8097 webpackDevMiddleware ( config ) {
8198 return plugins . reduce ( ( config , plugin ) => {
8299 if ( Array . isArray ( plugin ) ) {
@@ -95,9 +112,10 @@ const compose = (plugins) => ({
95112} )
96113
97114module . exports = compose ( [
115+ isProdBuild ? [ withPWA , pwaNextConfig ] : null ,
98116 [ withBundleAnalyzer , { enabled : process . env . ANALYZE === 'true' } ] ,
99117 [ withCSS ] ,
100118 [ withLess , lessNextConfig ] ,
101119 [ withSass , sassNextConfig ] ,
102- [ withPWA , pwaNextConfig ] ,
120+ [ withOptimizedImages , optimizedImagesNextConfig ] ,
103121] )
0 commit comments