Skip to content
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

Support a static data directory #2461

Closed
wants to merge 1 commit into from

Conversation

magcius
Copy link

@magcius magcius commented Dec 24, 2018

This is my take on the need to serve static data from the dev server.
Anything served from this path will be served as raw as possible, with
404s for missing files, and no index file.

Solves #1425 #1948 and maybe others.

↪️ Pull Request

@magcius
Copy link
Author

magcius commented Jan 20, 2019

Quick poke on this one again, since it is vital to my workflow.

@mischnic
Copy link
Member

What happens if you use files in that folder? e.g. <a href="data/..."> or <img src="data/...">

Related:
#1080

@magcius
Copy link
Author

magcius commented Jan 20, 2019

From my understanding, if the Parcel bundler logic pulls in "data/...", then it will serve the bundled version rather than the version from the static data dir. Should this happen? I don't know. One of the downsides to a "no-config" bundler is that when you have two competing conventions, you have to pick one of them, since you have no way of inferring the user's intent, and they can't configure it.

Currently, I only care about the XHR case, and as such this flag doesn't alter bundler behavior (it's a flag for the dev server, so it only exists on serve).

@magcius
Copy link
Author

magcius commented Feb 3, 2019

Can I request another review of this? I fixed the concern found two weeks ago.

@magcius
Copy link
Author

magcius commented Feb 19, 2019

Pushed an update. Can I get another review of this feature? The test failing doesn't look like my fault.

@magcius
Copy link
Author

magcius commented Mar 3, 2019

Another ping. Please. This is a blocking issue for my workflow.

This is my take on the need to serve static data from the dev server.
Anything served from this path will be served as raw as possible, with
404s for missing files, and no index file.
@devongovett
Copy link
Member

Perhaps we can just remove this check: path.extname(pathname) === '' since we serve the index.html if the file 404s. This way, if the file with no extension exists, it will serve it, otherwise, fall back to the index.

I don't really want to add another option for a static directory if we can help it.

@magcius
Copy link
Author

magcius commented Mar 3, 2019

Actually reporting a 404 error is an important part of my workflow. Additionally, this removes the need to place files into the dist/ folder, which is a bit sketchy since you might want to wipe it at any time.

@devongovett
Copy link
Member

This wouldn't change the existing 404 behavior. We have no way to know if we should emit a 404 or the index.html due to SPAs with client side routers. We need to serve the index.html so that the actual routing is delegated to the client.

@magcius
Copy link
Author

magcius commented Mar 4, 2019

This feature makes it so that if you pass --static-data-dir=data/, then any path that starts with /data/ is served "raw". So if the file path starts with /data/ and the file under it doesn't exist, it returns a 404.

@devongovett
Copy link
Member

I'm not sure I understand why this feature is necessary. We can fix the original bug of not serving files without extensions as I described above. I'd rather not add a new option to parcel if it can be avoided. Parcel will already copy files into the dist directory if they are referenced in the code (e.g. with import).

@magcius
Copy link
Author

magcius commented Mar 4, 2019

These are large binary files that I load at runtime (3D models) that I use XHR for. They can be 100MB in size. Importing does not seem like a smart idea. I would simply like to mirror this directory into the HTTP dev server, with typical "static data" rules (404s for missing files).

@devongovett
Copy link
Member

import assetUrl from './data/something.blob'

That will copy the file into the dist dir for you and give you back a URL to the final asset. It's not going to put the asset in your JS or anything.

@magcius
Copy link
Author

magcius commented Mar 5, 2019

The URLs to these assets are dynamically constructed at runtime, they are not static, so importing will not work. During production deployment I serve these assets from a separate CDN server. Please don't try to dictate my application architecture.

@devongovett
Copy link
Member

If it's a separate server in prod, you should make a separate server for dev to serve those assets as well so that the it matches prod as much as possible. I don't think it should be parcel's job to be a static file server in addition to a dev server. If you'd like to fix the original bug, please open a new PR.

@devongovett devongovett closed this Mar 5, 2019
@magcius
Copy link
Author

magcius commented Mar 5, 2019

Having two servers for development feels like a bizarre direction to go. However, it's possible that my needs here are unique. I might make my own server script based on Parcel's dev server library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants