This is a Next.js project bootstrapped with create-next-app
, with a couple of modifications to make sidepix work.
Export the site and serve it:
$ yarn export && yarn serve
There are two pages:
<picture>
example: http://localhost:8080next/image
example: http://localhost:8080/next-image
Images will be processed in development mode, too. Just reload until they're generated and cached.
$ yarn dev
sidepix's optimization server needs to import a PictureConf
object at runtime, so we have to compile it separately from Next.js's bundles.
Add a build-conf
script to package.json
:
"build-conf": "tsc --skipLibCheck src/components/PictureConf.ts --outDir conf",
"build": "yarn build-conf && next build",
In next.config.js
:
webpack: (config, { defaultLoaders }) => {
config.module.rules.push({
test: /node_modules\/sidepix\/.*\.js$/,
use: defaultLoaders.babel,
});
return config;
},
Call sidepix-wait
after next build
:
"build": "yarn build-conf && next build && sidepix-wait",
In a custom server server.ts
:
if (pathname?.startsWith('/media/')) {
await waitImage('public' + pathname);
}
await handle(req, res, parsedUrl);
Call the custom server instead of next dev
or next start
:
"dev": "yarn build-conf && yarn build-custom-server && node server.js",
"start": "NODE_ENV=production node server.js",