New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add development build feature to the razzle build script (on master) #1693
Add development build feature to the razzle build script (on master) #1693
Conversation
so that the razzle build script can produce a development build which is sometimes useful for testing using just a parameter --node-env=development see jaredpalmer#1289
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/jared/razzle/Dfd8hegKwM1hzaAA9aCP2T2ru6Tu |
that should remain local
@fivethreeo For some reason the command npm run build in the new example does not produce a dev build (I remember that, before this new PR, it produced a dev build). Now I have no idea how to make it produce a dev build.
The output files contain obfuscated and minified code. |
Oh, you mean dev in that way. Actually that has to be done for each case because razzle decides how to configure webpack by the 'dev' 'prod' string. So using 'dev' will start the server and add react refresh and hot reloading code. So we have to change that in createConfigAsync but IS_DEV and IS_PROD vars decide what plugins to add in big if blocks and also decides what mode webpack runs in and assumes we run in razzle start. So what we need to do is to check actual env and set a different webpack mode, set the dev tool, change splitchunks, disable terser, maybe change something in the define plugin options. This is sort of a legacy from early razzle and will need to be addressed better in the next major version. But we can fix it for now by brute force without changing the razzle api. |
'prod' and 'dev' should be 'start' and 'build' really, but backwards compatibility is a must until 5.0 |
I think I need to do this actually, needs lots of internal knowledge. But I can pull this one after I fix it 😀 |
Thanks. If you need some help from a beginner like me, please let me know, especially if my help can speed things up. I am restlessly waiting for the new version that has this feature. |
Are you able to try out the master branch? |
I think that in about 30 minutes I'll start an attempt. Thank you very much for your work! |
@fivethreeo How can I use npm link with the Razzle monorepo to reference the |
|
Pushed a fix, retry now |
Using yalc? |
Using |
Don't think you got the changes somehow, yalc works too. |
@fivethreeo Yes, you are right. |
The razzle repo is up-to-date, but npm link does not work. When I run
Does this look right? |
Not sure, I only use yarn. |
try rerunning npm install? |
I solved with Yalc and now I get:
|
Ah, sorry, I missed one ;) |
The masked log is here. Good night! |
When deploying, it requests the JS and CSS bundles from localhost instead of the domain name/IP address. It almost works. I think it has to do with the environment variable called RAZZLE_ASSETS_MANIFEST which is set by Razzle. |
It seems to me that on the remote server |
Fixed |
When running
Thanks. |
@fivethreeo The normal (production) build throws the same error. |
If you git reset to the previous rev is the assets inlined in
build/server.js
…On Sun, 22 Aug 2021 at 18:02, Silviu Bogan ***@***.***> wrote:
@fivethreeo <https://github.com/fivethreeo> The normal (production) build
throws the same error.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1693 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAADGV4JKAKVYYEHQOWX73T6ENRTANCNFSM5CRJS2XQ>
.
--
Øyvind Saltvik
|
I checked it, loaded by webpack and inlined. I will just undo the relative path :) |
By the way You can just run yarn try-example with-development-build In the razzle monorepo Then cd example
yarn build If you change something in razzle run yarn updateyalc In the example dir |
Now the remote server serves the JS bundle from e.g. |
The local development build also does not work. The JS and CSS bundles are requested from similar URLs but the response from the server is SSR. I want to take another look at with-webpack-public-path to see if I'm missing some functionality in the SSR server. |
What is the env vars in remote? |
Also does the remote run start:prod |
I have this part of code in the server: let assets: any;
const syncLoadAssets = () => {
fs.writeFileSync("env-vars.json", JSON.stringify(process.env, null, 2));
assets = require(process.env.RAZZLE_ASSETS_MANIFEST!);
};
syncLoadAssets(); that produces the following masked output in {
"USER": "root",
"SSH_CLIENT": "<some numbers>",
"SSH_AGENT_PID": "<some numeric ID>",
"XDG_SESSION_TYPE": "tty",
"SHLVL": "3",
"MOTD_SHOWN": "pam",
"HOME": "/root",
"SSH_TTY": "/dev/pts/0",
"nvm_current_version": "v12.22.5",
"DBUS_SESSION_BUS_ADDRESS": "unix:path=/run/user/0/bus",
"FORCE_COLOR": "2",
"LOGNAME": "root",
"_": "/root/.local/share/nvm/v12.22.5/bin/npx",
"PUBLIC_PATH": "http://<some IP address>:3005/",
"XDG_SESSION_CLASS": "user",
"TERM": "screen.xterm-256color",
"XDG_SESSION_ID": "<some numeric ID>",
"PATH": "/root/path/to/my/app/on/remote/node_modules/.bin:/root/.local/share/nvm/v12.22.5/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin",
"SSH_ENV": "/root/.ssh/environment",
"XDG_RUNTIME_DIR": "/run/user/0",
"LANG": "C.UTF-8",
"STY": "<screen session identifier>",
"SSH_AUTH_SOCK": "<irrelevant>",
"SHELL": "/usr/bin/fish",
"WINDOW": "0",
"PWD": "</absolute/path/to/app/dir/in/remote/server>",
"SSH_CONNECTION": "<some numbers here>",
"TERMCAP": "SC|screen.xterm-256color|VT 100/ANSI X3.64 virtual terminal:DO=\\E[%dB:LE=\\E[%dD:RI=\\E[%dC:UP=\\E[%dA:bs:bt=\\E[Z:cd=\\E[J:ce=\\E[K:cl=\\E[H\\E[J:cm=\\E[%i%d;%dH:ct=\\E[3g:do=^J:nd=\\E[C:pt:rc=\\E8:rs=\\Ec:sc=\\E7:st=\\EH:up=\\EM:le=^H:bl=^G:cr=^M:it#8:ho=\\E[H:nw=\\EE:ta=^I:is=\\E)0:li#41:co#140:am:xn:xv:LP:sr=\\EM:al=\\E[L:AL=\\E[%dL:cs=\\E[%i%d;%dr:dl=\\E[M:DL=\\E[%dM:dc=\\E[P:DC=\\E[%dP:im=\\E[4h:ei=\\E[4l:mi:IC=\\E[%d@:ks=\\E[?1h\\E=:ke=\\E[?1l\\E>:vi=\\E[?25l:ve=\\E[34h\\E[?25h:vs=\\E[34l:ti=\\E[?1049h:te=\\E[?1049l:us=\\E[4m:ue=\\E[24m:so=\\E[3m:se=\\E[23m:mb=\\E[5m:md=\\E[1m:mh=\\E[2m:mr=\\E[7m:me=\\E[m:ms:Co#8:pa#64:AF=\\E[3%dm:AB=\\E[4%dm:op=\\E[39;49m:AX:vb=\\Eg:G0:as=\\E(0:ae=\\E(B:ac=\\140\\140aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~..--++,,hhII00:po=\\E[5i:pf=\\E[4i:Km=\\E[M:k0=\\E[10~:k1=\\EOP:k2=\\EOQ:k3=\\EOR:k4=\\EOS:k5=\\E[15~:k6=\\E[17~:k7=\\E[18~:k8=\\E[19~:k9=\\E[20~:k;=\\E[21~:F1=\\E[23~:F2=\\E[24~:kB=\\E[Z:kh=\\E[1~:@1=\\E[1~:kH=\\E[4~:@7=\\E[4~:kN=\\E[6~:kP=\\E[5~:kI=\\E[2~:kD=\\E[3~:ku=\\EOA:kd=\\EOB:kr=\\EOC:kl=\\EOD:km:",
"PUBLIC_URL": "http://<SOME IP ADDRESS>:3005/",
"NODE_ENV": "production",
"PORT": "3005",
"CONNECTION_STRING": "<MongoDB connection string>",
"ABS_PATH_TO_CA": "<Some path to a certificate file>"
}
The development bundle of the app on the remote server is started with:
|
If you look in build/server.js what does webpack_public_path say? |
Try searching for localhost |
In .env.local, which is manually loaded in the server, I have: PORT=3005
PUBLIC_URL=http://localhost:3005/
PUBLIC_PATH=http://localhost:3005/
CONNECTION_STRING=<some MongoDB connection string> |
Not .env.local but .env.production should be loaded. I check NODE_ENV and based on that, in the server, I load either .env.local or .env.production. |
Does Razzle somehow load .env.local automatically? |
During build that is |
PUBLIC_PATH is a build time var only, that is what causes the confusion, use your own var in deployment. |
@fivethreeo I had to set RAZZLE_PUBLIC_DIR before build time and now this new feature works very very well! Thank you for your work! You are awesome! |
I often do process.env.PUBLIC_DIR||process.env.RAZZLE_PUBLIC_DIR |
so that the razzle build script can produce a development build (which is sometimes useful for testing) using just a parameter
--node-env=development
see #1289
Tasks
"prod",
as it was before and I don't know why it is was a mistake (?) but it solves this problem:--node-env
option, am I right?@fivethreeo Please let me know if you can help me with any of these tasks/questions listed above. Any feedback is appreciated. Thanks.