-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Parcel 2: Serving static data from the dev server #3407
Comments
We actually have something like this in parcel atm although it's kinda weird for this use-case. In theory we could add a folder like Another way to fix this is using our upcoming proxy config we're working on, see: #3281 for details |
I don't see why additional config is a bad idea. Parcel theoretically has similar cases with As you might be able to guess from the votes on #1080, this is a pretty well-requested feature that is important for a lot of use cases. |
I think ideally those files wouldn't just be copied or served by the dev server. They need to be part of the parcel asset graph as well. This will ensure they are watched, that things like HMR work, etc. |
Admittedly my use case is probably a bit out there, but my static data is over 1GB+ in size, and since I fetch it with XHR, there's no way URLs could be mangled. Think of anything big like videos. Having Parcel copy 1GB+ of data would be unfortunate to me. If we could watch the static data dir in its entirety and simply trigger HMR in that case, but otherwise serve it without copying, that would be fine. |
Hello, |
Maybe this is helpful in your case: {
"extends": "@parcel/config-default",
"transforms": {
"url:*": ["@parcel/transformer-raw"]
}
} you can import files which will then be copied to the dist folder: import file from "url:./static.json"
fetch(file)... |
That requires that all data is statically importable, no? If I have |
Correct (we just can't analyze the JSON file and guess which files you want to have available). |
Right, that doesn't work for my workflow, though it might work for some others. I am suggesting a data directory that can be monitored / served directly. |
Hey, just also wanted to mention that these assets are:
So it definitely needs a directory that the app has access to when it's running. |
This plugin was sufficient for my use case. |
Any word on progress on this? It's baffling that you spent all this time to make Parcel and Parcel 2 but it can't do the most basic of tasks which is serve up unaltered static files. |
I think you should be able to use some static middleware with the proxy functionality: https://v2.parceljs.org/features/api-proxy/#.proxyrc.js |
Based on @mischnic 's advice, Now I can serve static files of Create
Then you may access your static file like this |
Following @subuta's lead, I went with the approach I had used in my webpack-dev-server config (but pasted into
|
Hi, I had the same issue, but for me the So I made this simple plugin that takes care of copying multiple folders and files into the specified folders once the build finishes successfully: |
hey there @magcius, just ran into the same issue here, still don't understand why parcel doesn't have this feature built-in. check this out: |
I have to use json-server to serve static files since parcel.js does not support it (parcel-bundler/parcel#3407).
Seems to me having a Amazing that it needs so much discussion.... The folder doesn't have to be watched or anything. There is no expectation that changing static assets under All we need is for a folder (commonly named 'public') to be exposed under the root so that 'http://localhost:1234/my/file.txt` maps to I think you could include this as standard. Because the convention to have a |
I'm a new Parcel user who got lured in by "The zero configuration build tool for the web." I've spent about 3 hours on this so its certainly a problem for new users. Everything else seems great though. Would of loved a |
+1... |
it's a bit hard to believe that Parcel lacks such a simple config option to have a sort of "public" folder that:
I do understand the concerns of messing with existing codebases, but this shouldn't really be a problem if:
I'm back to this thread after more than a year, looking for the same thing. I was hoping that something changed during this time. I went with the "serve-static" plugin but that is only useful during dev time. For build you need to do your own copying if you need those files. |
You should make the dependency on assets explicit in your code, e.g. using |
As I said nearly five years ago:
|
Parcel is fantastic, but the inability to serve static files without forcing them through the build pipeline is a blocker for many modern web apps dealing with large assets like videos or datasets. A solution for a simple static folder would greatly enhance the development experience and align with Parcel's 'zero configuration' philosophy. For comparison, Vite achieves this easily with a public directory for static assets, as seen here: https://vitejs.dev/guide/assets#the-public-directory. |
It's definitely already possible. I think this comment from 4 years ago is basically the solution I'd recommend: #3407 (comment) I think we should just document this (parcel-bundler/website#655). This approach gives you full control of how files are served, e.g. under what URL prefix, what directory or directories to serve, what caching and other headers to apply, where to copy to the dist dir for production builds, etc. We could add a "public" folder convention, but then we'd have to make all of that stuff configurable anyway. This could get complicated very quickly, e.g. supporting multiple different sources to serve/copy files from, different renaming patterns, etc. It seems much simpler to just use existing tools like express middleware and the |
🙋 Feature request
Currently, there's no way easy way to add additional data into the dist dir provided by serve. I've previously advocated for this use case (#2461), where I have large binary files like 3D data that I do not want to push through the build process. The intermediate workaround has been to place a folder symlink into the dist/ directory, which works OK -- I can filter out
text/html
responses on the client and pretend they are 404s.Parcel 2 moves the dist dir into .parcel-cache, and seems to more aggressively wipe it. This means it's very hard to get Parcel 2's dev server to serve static data again. The code for serving static data is still there, however.
🤔 Expected Behavior
I would like a supported mechanism to serve static, unbuilt data from the Parcel dev server.
😯 Current Behavior
There is no way to serve static data, and the existing workarounds for Parcel 1 which were relied on by many is now effectively unusable.
💁 Possible Solution
Support extra configuration to the parcel dev server, either based on the code in #2461 or not.
🔦 Context
I believe I have provided a sufficient amount of context above.
The text was updated successfully, but these errors were encountered: