Skip to content

Commit f592712

Browse files
authored
Add image support (#4)
1 parent 06dde18 commit f592712

File tree

3 files changed

+1508
-34
lines changed

3 files changed

+1508
-34
lines changed

next.config.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ const withCSS = require('@zeit/next-css')
55
const withLess = require('@zeit/next-less')
66
const withSass = require('@zeit/next-sass')
77
const 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

916
const 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+
4460
const pwaNextConfig = {
4561
pwa: {
4662
dest: 'public',
47-
disable: process.env.NODE_ENV === 'development',
63+
disable: !isProdBuild,
4864
},
4965
}
5066

5167
const 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

97114
module.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
])

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
"esm": "^3.2.25",
2222
"firebase": "^7.15.5",
2323
"firebase-admin": "^9.4.2",
24+
"imagemin-mozjpeg": "^9.0.0",
25+
"imagemin-optipng": "^8.0.0",
2426
"less": "^4.1.1",
2527
"next": "10.0.1",
28+
"next-optimized-images": "^2.6.2",
2629
"next-pwa": "^5.0.1",
2730
"null-loader": "^4.0.1",
2831
"raw-loader": "^4.0.2",
@@ -33,7 +36,8 @@
3336
"reactfire": "^3.0.0-rc.0",
3437
"redux": "^4.0.5",
3538
"sass": "^1.32.8",
36-
"swr": "0.2.3"
39+
"swr": "0.2.3",
40+
"webp-loader": "^0.6.0"
3741
},
3842
"license": "MIT",
3943
"devDependencies": {

0 commit comments

Comments
 (0)