How to make the server send the styles and the scripts to the client in production? #1639
-
In development it works, otherwise I would have looked better at the server.tsx file. I tried with npm start, it works, but... I tried with npm run build, it works, no errors.
but it does not load styles or scripts, just the SSR HTML. I read this https://razzlejs.org/docs/environment-variables and it is not obvious to me what should I set to what. This is what I've tried without the wanted great success: PUBLIC_PATH=http://localhost:3005/
CLIENT_PUBLIC_PATH=http://localhost:3005/ In the .env file I also have: PORT=3005
BROWSER=chromium
RAZZLE_PUBLIC_DIR=public/
PUBLIC_URL=http://localhost:3005/ and I have some old code in it too, that I'll remove after posting this. I think it is irrelevant for my question: REACT_APP_API_URL=http://mydomain.com/api
SKIP_PREFLIGHT_CHECK=true Thanks! Update 1I see that the server sends the script to the client but when trying to open the script in Chromium I am redirected recursively into http://localhost:3005/static/js/error/error/error/.../error/error-v1 where [...] means it is expanding with each tick of the clock. If it is useful information, I use react-router-dom and StaticRouter for SSR but I think the issue is something else, like accessing a JS file redirects to one of my routes, somehow JS files and the routes get too related. Thanks. Update 2With this line commented out, # CLIENT_PUBLIC_PATH=http://localhost:3005/ I can get npm start to work, but when it is there, as it makes sense, npm start does not work. Nor does the npm run start:prod. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Don’t set RAZZLE_PUBLIC_DIR razzle does that itself. |
Beta Was this translation helpful? Give feedback.
-
Dev media is on PORT+1 so in your case 3006 |
Beta Was this translation helpful? Give feedback.
-
https://github.com/jaredpalmer/razzle/tree/master/examples/with-webpack-public-path |
Beta Was this translation helpful? Give feedback.
https://github.com/jaredpalmer/razzle/tree/master/examples/with-webpack-public-path