-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.config.mjs
38 lines (36 loc) · 1.14 KB
/
next.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { build } from "velite";
/** @type {import('next').NextConfig} */
// eslint-disable-next-line import/no-anonymous-default-export
export default {
// othor next config here...
webpack: (config) => {
config.plugins.push(new VeliteWebpackPlugin());
return config;
},
images: {
remotePatterns: [
{
protocol: "https",
hostname: "github-readme-stats.on-cloud.eu.org"
}
]
}
};
class VeliteWebpackPlugin {
static started = false;
constructor(/** @type {import('velite').Options} */ options = {}) {
this.options = options;
}
apply(/** @type {import('webpack').Compiler} */ compiler) {
// executed three times in nextjs !!!
// twice for the server (nodejs / edge runtime) and once for the client
compiler.hooks.beforeCompile.tapPromise("VeliteWebpackPlugin", async () => {
if (VeliteWebpackPlugin.started) return;
VeliteWebpackPlugin.started = true;
const dev = compiler.options.mode === "development";
this.options.watch = this.options.watch ?? dev;
this.options.clean = this.options.clean ?? !dev;
await build(this.options); // start velite
});
}
}