-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.mjs
31 lines (27 loc) · 931 Bytes
/
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
import { build } from "velite";
const nextConfig = {
webpack: (config) => {
config.plugins.push(new VeliteWebpackPlugin());
return config;
},
};
// Export the variable as the default export
export default nextConfig;
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
});
}
}