diff --git a/next.config.js b/next.config.js deleted file mode 100644 index 60c9cc1..0000000 --- a/next.config.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @type {import('next').NextConfig} */ -const nextConfig = { - reactStrictMode: true, - swcMinify: true, - webpack: config => { - config.plugins.push(new VeliteWebpackPlugin()) - return config - } -}; - -class VeliteWebpackPlugin { - static started = false - 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' - const { build } = await import('velite') - await build({ watch: dev, clean: !dev }) - }) - } -} - - -module.exports = nextConfig; \ No newline at end of file diff --git a/next.config.mjs b/next.config.mjs new file mode 100644 index 0000000..2bfb7d9 --- /dev/null +++ b/next.config.mjs @@ -0,0 +1,14 @@ +const isDev = process.argv.indexOf('dev') !== -1 +const isBuild = process.argv.indexOf('build') !== -1 +if (!process.env.VELITE_STARTED && (isDev || isBuild)) { + process.env.VELITE_STARTED = '1' + const { build } = await import('velite') + await build({ watch: isDev, clean: !isDev }) +} + +/** @type {import('next').NextConfig} */ +const nextConfig = { + swcMinify: true, +}; + +export default nextConfig; \ No newline at end of file