Skip to content

Commit

Permalink
feat: velite plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
zce committed Mar 24, 2024
1 parent 42a5650 commit 344471d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
28 changes: 13 additions & 15 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
import "./env.mjs"
// import { build } from "velite"
import { build } from "velite"

/** @type {import('next').NextConfig} */
const nextConfig = {
images: {
domains: ["avatars.githubusercontent.com"],
},
webpack: config => {
// config.plugins.push(new VeliteWebpackPlugin())
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'
// await build({ watch: dev, clean: !dev })
// })
// }
// }
class VeliteWebpackPlugin {
static started = false
apply(compiler) {
compiler.hooks.beforeCompile.tapPromise('VeliteWebpackPlugin', async () => {
if (VeliteWebpackPlugin.started) return
VeliteWebpackPlugin.started = true
const dev = compiler.options.mode === 'development'
await build({ watch: dev, clean: !dev })
})
}
}

export default nextConfig
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"scripts": {
"dev": "next dev",
"build": "velite && next build",
"build": "next build",
"turbo": "next dev --turbo",
"start": "next start",
"lint": "next lint",
Expand Down

0 comments on commit 344471d

Please sign in to comment.