Closed johhansantana closed 6 years ago
You should be good just by running npn run build
and then just point out the build folder to zeit-cli while hosting it.
Personally, I would just use this:
"scripts": {
"start": "preact serve",
"build": "preact build",
"watch": "preact watch"
}
ZEIT will automatically run a build
command if it's detected. Also, this way, you don't have to worry about env-vars, which are specific to now.sh
only.
I changed it to @lukeed example but it fails when creating the SSL on now
:(
> > preact serve
> Setting up SSL certificate (may require sudo)...
> Attempting to spawn simplehttp2server to generate cert.
> Failed to generate dev SSL certificate: Error: spawn /home/nowuser/src/node_modules/simplehttp2server/vendor/simplehttp2server_linux_amd64 ENOENT
Oh right, they provide ssl for you on their end.
Install serve
and then use it for your start command. I'm not at my desk but it's something like serve build -s
where the s
flag signals SPA mode.
It worked with serve build -s
thank you! Man this is so mind-blowing how performant this preact-cli library is.
Thank you.
Hey, @johhansantana, would you mind posting your package.json config that got it working? I'm struggling with the same error.
What was the fundamental issue?
@fardarter and anyone else whom happens across this, some vendors on deploying do SSL automatically (like now). Instead of using preact's build in web server, like @lukeed lukeed suggested, you can use serve
Add serve as a dependency:
npm install serve --save
or yarn add serve
Edit your package.json to use serve
instead of preact serve
. It should look something like this:
{
"scripts": {
"start": "if-env NODE_ENV=production && yarn serve || yarn dev",
"build": "preact build",
"serve": "serve build -s",
}
}
Or, for those pesky CI's that don't run the build command:
{
"scripts": {
"start": "if-env NODE_ENV=production && yarn serve || yarn dev",
"build": "preact build",
"serve": "npm run build && serve build -s",
}
}
If your deploying using now, just run: now -e NODE_ENV=production
And it should build correctly.
When I try to deploy to zeit.co now it builds and runs but only the development server.
Do I need to setup the
NODE_ENV
to production? If so, where do I do that?side-note: This library is awesome!