-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Provide a watching build mode that writes to the disk in development #1070
Comments
My concern: the concept of a dev server is already confusing to many people and I've seen countless issues from people trying to find dev server output in the filesystem, adding scripts with hrefs to local files, when they didn't need it. So I'm worried introducing this feature is useful in some advanced cases but might make everything more confusing in simple cases for people who mistakingly start with |
(As the OP of #1018) :
@gaearon makes a great point saying that CRA biggest win is saving the developer from configuring the dev server which is the most difficult feature. I'd be happy if at least we could access the dev bundle.js file from the filesystem, I wouldn't care if the dev server is started, I would just ignore it. My argument is that: CRA is quite appealing to non Node.js developers. There are many experienced developers in python, php, .net out there, but not all of us/them are that experienced in frontend set ups. CRA makes it a no-brainer to use react. And to be honest, these days it's way more difficult to set up a React project than an ember or angularjs 1.x project. React API is pretty simple and powerful, but when you introduce React to your organization projects, it's not just React, but all its friends which are hard to master (webpack, babel, presets, linters, etc). Not sure if you guys have read this blog post yet https://goo.gl/HviDRn, but it's about a company that has a backend in Flask and were evaluating a frontend framework. They talk about how difficult is to keep up with the shifting ecosystem around React, and I'd totally agree on their pain points. At the end they chose Emberjs because of their CLI tools that makes it super easy to integrate. I think CRA was created with the mindset of helping people that are just starting with React, and playing around with a few simple tutorials, but it has the potential of becoming a profesional tool for people that don't have that much time to spend learning webpack, babel, if to use We need something opinionated that just works. Note that I'm totally fine with the already existing features in CRA. Sorry for the long post. |
Tagging with a milestone so I remember to get back to it. |
I think this is the same as #1316 should i just close that? |
Yea, this is the same. |
Isn't this can be solved with proper documentation and gentle reminder when they use this feature? Would be happy to working on a react-scripts watch PR. I have 'ejected' several project because i need this feature. |
I'm not opposed to adding it. Happy to take a look at a PR. |
I'm currently using The only problem is that appending the hash to the bundle's name |
I want to add an additional story to add context to why I'd like this feature: We built our app with server side rendering and waited until we had a feature that would require enough js/ajax to justify a single page app. We got to that point and wanted to replace that one page with a react frontend. The plan would be that react would gradually expand to the rest of the app (if needed, maybe it'd never be needed). But CRA appears to assume that in development mode, your frontend is a different app from your backend. That's not necessarily true if you want to bring react to an application that already exists. (Even if you go with the dual-app idea, you have to deal with CORS. I think you could argue that CORS complexity outweighs the output file complexity.) So our workaround is to always build to production and copy the files into our server so they can be rendered. But the minification and source map generation adds an extra 10-15 seconds when we do that every time and we can't use a watch. When you want frequent, fast feedback loops, those 10-15 seconds add up to considerable lost time. Let me know if I'm doing something wrong here. Maybe there's an obvious workaround here. |
Thanks for your reply. @viankakrisna I don't see how #1994 & #1588 add up to a development mode where you can have a single page of your app use react. |
I'd just like to echo all the above, when loading resources from an external file it's a huge pain for the names to change every time you make a small change and rebuild. |
Great to see this being discussed. |
Applies the patch from this abandoned PR: facebook#7812 Based on this 4-year-old issue about emitting dev builds to disk: facebook#1070 To use, call `react-scripts start --writeToDisk`. This will emit dev environment built files to the normally-production output path.
@pupudu, was looking at your PR just now, looks like it changes the publicUrl as well as other unrelated behavior based on the flag (whether or not to open the browser). Just wanted to raise that there are many use cases for writing the dev bundle to disk outside of serving dev assets with a different server, that might require the publicUrl to remain unchanged: For instance, building an unoptimized build for faster CI (#1960, #1070 (comment)), developing browser extensions (#1070 (comment)) or electron apps (#1070 (comment)) using the CRA dev server for faster feedback loop with fast refresh and faster builds (no need to optimize), and for interacting with other developer tools that might make use of the unoptimized bundle (I'm actually working on something right now that processes dev bundles, and currently it requires patching CRA). I think @ioloie's PR (#6144) that only adds a |
I've been using https://www.npmjs.com/package/cra-build-watch as a work-around for this issue. I like the idea of a |
@bjankord Thanks for the hint! It serves perfectly for my need as well. It would be very nice to have this feature out of the box. Anyway, https://www.npmjs.com/package/cra-build-watch works just great!!! |
This feature would be extremely useful for anyone who's trying to inject some server data or trying to do some server-side templating instead of just serving the This blog explains the use case very well. Also #1703 The main problem with trying to use Express with create-react-app is that We already have cra-build-watch that does this. Isn't there a way to include that feature as part of create-react-app? It doesn't have to be the default behaviour but something the user can enable with a flag when they know what they want. |
I'm working on CRA + SSR, this feature would be appreciated. |
I seriously can't understand this bug is open for 5 years already. If you want to give a prototype to testers, you want the version deoployed, but with full debug informations for recording the tracebacks etc. I don't understand why there is no debug build, seriously, I have not seen any compiler that forces you to build optimized builds only.... |
Agreeing with @poelzi |
Can someone confirm that this makes CRA absolutely useless for use cases where you want to do things like run your data access (to indexeddb, for example) only via the service worker? It appears that the service worker file is only generated for production builds, meaning the sws can only be used for caching, and nothing "serious". Is that the current situation or have I missed some completely obvious way of doing this? |
I got it worked with Craco.
This will output the files under |
I have an existing template-based/jekyll site that is adding pages built with React and introduces a header that is a React/bootstrap component to existing pages. Running a dev server is fine for testing the newer content, but right now I want to debug some details that relate to the integration with the pre-existing site whereby I want to test a full build, as it will run in production, except disable things like javascript minification. It seems surprising that you can't just do something like |
Wow, this is old. Any movement on this issue? |
Any update on this issue? |
More than five years has passed!! This would be a very nice feature!! |
My use case is that I am using firebase which has emulators for local development. I don't care if the development server uses the re-build output, or even if it is the same output. I just want a watch option for |
This is how I was doing it before, but it seems craco doesn't support cra v5. |
This issue can be easily solved with the npm package run-when-changed with the command: ./node_modules/run-when-changed/bin/run-when-changed.js --watch "src/*.js" --exec "npm run build" or a NPM command in scripts like: {
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"build:watch": "run-when-changed --watch \"src/*.js\" --exec \"npm run build\"",
}
} Another advantage, it is not dependent on React or CRA version. |
This works, thanks, but the configuration should now be:
|
after a lot of years this shit still is unable to create an unoptimized build in simplest way |
I was trying to create a POC for a development framework for react, nodeJS and I got here. Reading all these. Is it really hard to add an .env or a "-- switch" to write an unoptimized the build to disk? :) |
I am trying to debug and run like we do in production where react is served FROM the server(nodejs) and I have that working but it is serving the 'optimized version' and I would love to serve the unoptimized vesion and make things a bit faster. Like someone before, if only react-scripts start 'actually wrote the output to the filesystem in the build directory or something' which can be blown away on a react-scripts build, that would be wonderful. For now, I had to hack a "dev": "npx nodemon --watch src --ext ts,js,tsx,css --exec "npm run build"", but it is slow because it is doing an optimized build unfortunately. |
That is what I did but it is createing an optimized build so it is very slow :( so iterating is really a PITA the larger the app is. |
See #1018 (comment) for a discussion which leads to the creation of this issue.
I propose adding a new command (working name
build-dev
) which watches for changes and rebuild the bundle (effectively, given the current CRA implementation, it should executewebpack --watch
), then writes it onto filesystem.The main motivation is an easier integration path with non-Node.js dev servers: such servers could just serve continuously updating bundle from the filesystem.
The only desired configuration options is an
--output
, which could probably be specified via a command line argument:Alternative command name suggestions:
watch
build-watch
The text was updated successfully, but these errors were encountered: