Next CLI as a package
Answered
Tosa posted this in #help-forum
TosaOP
Is it possible to use the next.js CLI as a npm package? Instead of using spawn in node is there a way to require next and call the commands it as a function?
Answered by joulev
ah that's what you meant. in that case there is no existing guide on that, but why don't you simply
or have a
{
"scripts": {
- "build": "next build"
+ "build": "node prebuild.js && "next build"
}
}or have a
prebuild script6 Replies
@Tosa Is it possible to use the next.js CLI as a npm package? Instead of using spawn in node is there a way to require next and call the commands it as a function?
yes, see [Custom Server](https://nextjs.org/docs/pages/building-your-application/configuring/custom-server), but there is are no similar guides for the app router at the moment
TosaOP
Thanks. Apologies for the confusion I meant for building. I have a
build.js node script that prepares all the env variable, config, etc. Was just wondering if I can initiate the next build from within node without having to rely on spawn.@Tosa Thanks. Apologies for the confusion I meant for building. I have a `build.js` node script that prepares all the env variable, config, etc. Was just wondering if I can initiate the `next build` from within node without having to rely on spawn.
ah that's what you meant. in that case there is no existing guide on that, but why don't you simply
or have a
{
"scripts": {
- "build": "next build"
+ "build": "node prebuild.js && "next build"
}
}or have a
prebuild scriptAnswer
it's quite common to have something like
node prebuild.js && next build as well, e.g. if you use prisma you will do prisma generate && next buildso it's not an anti pattern or something like that, you can run anything before or after the build and it is perfectly fine
TosaOP
👠Okay, thanks for that.