-
Notifications
You must be signed in to change notification settings - Fork 4
/
next.config.mjs
33 lines (29 loc) · 1012 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
32
33
import { build } from "velite";
import dotenv from 'dotenv';
dotenv.config();
/** @type {import('next').NextConfig} */
export default {
// othor next config here...
webpack: (config) => {
config.plugins.push(new VeliteWebpackPlugin());
return config;
},
};
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
});
}
}