-
-
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
[RFC] Specify sub directory for all the generated assets for easy deploy and serve #233
Comments
Is this essential to making SPAs? Can we avoid having to add more to our CLI by just letting NGINX handel all of this rather than parcel? |
@davidnagli An SPA was my initial use case (and used in my example), though I'd like to see it as a generally nice feature just to to be able to say where my generated files shall end up. As for the SPA case -- leaving the generated structure flat with no options (leaving the web server to handle this) is really not very ergonomic in the general case. Again, makes for a really smooth developer experience, which is something I sensed is a goal of this cool tool. |
Ya I definetly see where you’re going with this. It seems like a pretty important feature. How do you think we should implement this? The whole point of Parcel is that there is no configure file, so we would want to implement it in a way that’s very automatic. I just can’t figure out how to design it in a way that is actually easy and productive for developers. |
wouldn't nginx's
this will make nginx to try and serve a file under the request uri and otherwise fallback to it might be worth creating a guide for such case for common web servers. |
@mrbar42 that's a nice one, but nginx and/or SPA are not the only reasons to need the generated files/assets to be easily distinguished in the general case -- be it in the form of naming a directory for them or having the files prefixed or whatever. @davidnagli What would the major problem be with a cli option like the existing |
From an SPA development perspective, is it essential that we give you control over the name of that directory ( |
@davidnagli That would be the next best thing I suppose (and not only for SPA use cases, sorry if that part of my argument stuck), in that it facilitates various post build operations. I really can see (and appreciate) the effort to keep the configuration explosion on a leash. Though I foresee continuous proposals about being able to name the |
I also have the same problem:
For example, the following is the file structure of the backend rendering project based on express
parcel is great, packaging efficiency is very fast, but it can not configure the corresponding file path, a bit regrettable... But I'll still pay attention to it |
Is this still not possible? I have a Flask app with the following structure:
By default, Flask apps serve static content (js, css, images, etc) from I want Parcel to bundle the files from Currently everything is put into a Ideally, to cater for all types of projects, it should be possible to specify different output directories for different entry points. In Webpack, you can specify to output css into |
Would love to see some official word on this. I don't find much sense for a project where the This is the one issue where I find Parcel's "no config" approach to be a fatal flaw as it basically defines how all projects must be structured and does so without any logic. |
Imho Parcel should recreate the existing project structure for imported files. This would allow infinite flexibility (users could just do whatever and it would work for them) and it could always be overwritten using a config file. |
This would be useful for me too, maybe even a /assets/ folder or anything similar so when i have 200 + images they arnt all in the root |
I've run into this limitation today. I was about to add this line to the express app: app.use(express.static(path.join(__dirname))); to serve all the web-app assets but clearly this would be really bad because with the build folder being flat that means |
@Place1 how would that happen? do you store your if your project looks like this
then you should do something like this app.use(express.static(path.join('dist'))); which wouldn't expose your server code |
I run my backend through parcel to concert jsx using —target=node
My sister folder has client/ and server/ in it. I make use of the —out-dir
flag.
…On Tue, 14 Aug 2018 at 5:34 pm, MrBar42 ***@***.***> wrote:
@Place1 <https://github.com/Place1> how would that happen? do you store
your index.js in the dist folder?
if your project looks like this
-/
- dist/
- *.{html,js,css,png,woff2,...}
- index.js
then you should do something like this
app.use(express.static(path.join('dist')));
which wouldn't expose your server code
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#233 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALMBlg0GVEQGXhaB97IpVvNTQclsq-5Kks5uQn2JgaJpZM4Q-vNR>
.
|
then you can call parcel twice with different |
Yeah that’s what I’m doing. But it’d be nice not to have to.
…On Wed, 15 Aug 2018 at 12:42 am, MrBar42 ***@***.***> wrote:
I run my backend through parcel to concert jsx using —target=node
then you can call parcel twice with different out-dir, once for the
clinet with dist/client and once with dist/server
and have your express static point dist/client
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#233 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALMBlux6lpM7lA6O_ZtWPtYOY9BiY1f7ks5uQuHjgaJpZM4Q-vNR>
.
|
I was surprised to see that if I have a folder structure:
Everything would just be dumped out in a flat file structure in the |
Yes! This is exactly what I meant. |
It's hard to make this the standard as you could end up having a very deeply nested tree. And in most cases it just gets dumped onto a server anyways, besides that some terminal magic and you can find any file in seconds no matter how flat and big the folder is. Note: this will be possible once parcel 2 gets released as you'll be able to use your own naming strategy (or a premade one {the default will remain the same}), this will allow anyone to use hashes, filenames and folders however they want |
I don't think we'll support recreating the entire source file structure as it could be quite deep and nested as Jasper mentioned. I could see supporting a single "assets" directory where content hashed files could go, with other entry points at the top. That being said, in Parcel 2 you'll be able to override the naming strategy using plugins, so I assume the community will come up with some good options for different use cases which we can bring back into core as needed. |
Closing this since it will be solved in Parcel 2 via plugins. |
ディレクトリ分けは現在のバージョンでは対応不可。 次のv2から対応できるみたいです。 parcel-bundler/parcel#233
I would like to add a possible solution to create high-level asset folders:
which creates:
|
My plugin makes it, based on the publicURL : https://www.npmjs.com/package/parcel-plugin-pre-dist |
give us more information about usage of your plugin.. |
When developing parcel does not use the dist folder. This means that if you copy assets to the dist folder, the server cannot see them. So when using something like parceljs etc they're not visible during development and cannot be tested. His plugin allows you to set a pre-dist folder, which you can copy your assets to. This means that you can test assets in development. |
The solution for this problem and any other asset naming and structure is can be solved by a "custom Namer plugin" in Parcel 2:
|
When will Parcel 2 be released(stable)? |
This question has been bothering me,Hope that the official solution |
Has this changed since then, because when I run parcel it definitely does. Which is annoying as hell as I really want parcel to be THE tool to use for web development, but at the moment it seem to still be in its infancy and not ready for production. |
I have created a Parcel 2 namer plugin which puts assets into a directory called |
Having this issue for too long, I've decided to make a plugin that will solve this. Look how simple it is!First, install it by running In your "customDistStructure": {
"config": {
".css": "css",
".js": "js",
"images": [
".jpg",
".svg",
".png"
]
}
}, # Build your project
parcel build index.html Congratulations, this your dist folder:
Let me all know what you think! |
Is there built-in functionality in version 2 to configure output directories or do I need to install a plugin? If I need to install a plugin, which plugin? I tried VladimirMikulic's plugin but apparently, the plugin only works for Parcel version 1. The link to version 2 takes you to somewhere seemingly unrelated. I would be surprised if there isn't built-in functionality for something so basic. |
TLDR;
My point is that serving the built project (both in prod and dev) could be so much easier in the common case if generated assets were not necessarily put alongside the main index file -- and an option for it could carry its weight.
What am I talking about?
Consider having a
src/index.html
file, referring css and js files (living anywhere in the src tree).Without any options used when bundling the resulting assets are generated alongside the index.html in
./dist/
like:-- and the index.html is rewritten to refer them nicely.
SPA stylee, the
dist
folder is to be statically served by nginx/equivalent, and for a seamless dev experience I'd like to deploy it as is -- or even build it in place on Heroku or such.For that, I would love a build option to say "all the generated assets should live in a sub directory by the name of foo". (We already have an
output-dir
option, which sets the name of the whole build output, and apublic-url
option, though the latter just affects the referring paths in index.html (in this case) ).This could the the result of my idea:
That way nginx/whatever could happily serve index.html for all requests but
foo
and under.An alternative would be
public-url
option to have index.html refer assets infoo
dist/foo
, but this juggling does not work very well in development mode, wanting nginx to serve files in the same manner from the local
dist/
.Creating a more elaborate bunch of rules for the file server to have it avoid serving index for any generated asset file is another cumbersome route I'd happily avoid :D .
The text was updated successfully, but these errors were encountered: