-
Notifications
You must be signed in to change notification settings - Fork 28
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
Make public directory location configurable #56
Comments
Haha, thanks! Pretty sure I can still increase the performance! From reversing Rollup, the behaviour that 0.9.0 matches Rollup in terms of the Rollup API. When you run a build using Rollup using However! If you use If using the As far as I can tell, Rollup and Nollup are aligned here. The core difference is that when you're using Rollup in that scenario, it's using To clarify:
|
That must be it then. I can't really tell about the programmatic API, never really used it yet. So no problem for me on this side!
But what about multiple output files? output: [
{ file: 'public/app/index.js', format: 'es' },
{ file: 'public/vendor/index.js', format: 'es' },
], How do I set Also, if Nollup completely drops the parent directories, one of them will not be accessible because they will have the same However if What approach were you thinking about? |
If Is there any particular reason |
Maybe
I hadn't really dug into it, to be honest. But now that I try, I get mixed results. I manage to get what I want, that is to have my bundle served at export default {
input: './src/main.js',
output: {
dir: 'public/build',
entryFileNames: 'build/bundle.js',
},
plugins,
} I fail however to get it working with I've pushed a new branch to my test repo (will need to rename that playground) that illustrates what I'm doing with Rollup and failing to achieve with Nollup. Do you have any suggestion on how to make it work? As a side note, it seems that Nollup has no support for multiple output targets (see example on another branch). Still possible that I'm missing something obvious, though... For a real world example, this is used in Svelte's component-template. Anyway... Support for That being said, since a workaround is possible with |
Hmmm, I was thinking about this throughout the week, and here's some thoughts I had:
|
I agree with your first point. Since that's mainly a serving issue, it seems logical that it should be addressed at the middleware level. The question remains though: what will be the URL for a file that is written under the public directory (the one setup as
Actually, I think it was more a bad example on my part. It wouldn't be possible to do that with Rollup this way either, would it? Anyway, that's not really a need I have, I just noted the misalignment with Rollup while exploring for the public dir issue. I don't have a solid opinion about what should be done in this area. |
That's a good question, and it was something I was wondering. A typically project would have something like the following folder structure:
With the The problem then comes when you use I've been looking into Webpack as to how they've addressed this, but this seems like this is an exclusive problem for Rollup configs. Webpack has a separation of output directory and bundle filename options, rather than a single option. So there's no precedent to follow as far as I can tell. There is this: https://github.com/rollup/rollup-starter-app, I don't think it's a great pattern because it's mixing build artifacts with source code (they have added a gitignore rule for this though). So maybe it has to be one of those things where contentBase has to be auto-detected in the file output path. |
I would have agreed with you wholeheartedly... But, look who did it, and again, and when pushed about it... He doubles down. Clearly, there's something going on here. I'm not in his head, but I think he does all this in the sake of reducing complexity for newcomers. Like with Rich seems all bent on the easiest possible first contact for beginners, followed by an optional and postponed increase in complexity, as per the needs & desire of the user. Each of these are little things when taken individually. But, as a whole, they end up making the difference between Webpack's API and Rollup's. Since this pattern has been consistently endorsed and popularized by Rollup's author for years, I feel compelled to take my own opinion with a pinch of salt here. At the very least, I think it means the pattern should be supported.
I think the higher level final goal is pretty well defined: since Nollup acts as Rollup + a web server, it should behave like Rollup + a web server would do. A web server would serve all files in its "web root" directory, with URLs being the path of each file relative to the public directory. I can't think of a straightforward way of implementing this, except by doing exactly the same thing. That is (1) to make Nollup generate the same file paths in its head (memory) as Rollup would have written to disk, and (2) to compute the URL as this path relative to the public dir. The benefit of this approach is that it deconflates the responsibilities of generating output filenames vs generating URLs. This way, you don't have to think & test URLs as a function of output options. Rather, you can implement & test them independently of each other. On one hand you've got fs paths as a function of output options: they're good when they're the same as Rollup with the same options. On the other hand, you've got URLs as a function of fs paths. And when the specs of one or the other will change, for example because someone ask for support of multiple public directories, only the relevant part will be affected. |
Hey! Unfortunately, I'm not sure I'll have time to write a proper issue for the But I just wanted to let you know that this issue is currently more important for me. I am reluctant of introducing Like I said previously, I've got ways to live with it, so I don't mean to press you by any means. And I still have to fix support for last Svelte version on my side... On the contrary, I want to thank you for all the help and the work you've done so far! Just letting you know about my own current priorities, in case that's useful for your decision making ;) |
Oh don't worry about it at all. I love hearing about all of the issues as it helps to make the project work better for people. 🙂 This issue is the first on my agenda that should hopefully be addressed this week! 😁 |
https://github.com/PepsRyuu/nollup/tree/FileOptionServe Dev middleware takes care of the following now:
Going to be writing test cases for dev middleware. Let me know what you think! |
Sorry for taking so long to come back at this... Totally got sucked into "must deliver before Christmas" and stuff! So, reusing It feels a bit like your surfing the tip of the happy path with this but I can't think of a case where it wouldn't work, so heh... I tried the branch in the Svelte template. Works great for my current needs, that is For more advanced usages though (dynamic imports / code splitting next in line), it seems that Rollup and Nollup are not aligned on URLs with input: 'src/main.js',
output: {
format: 'esm',
dir: 'public/build',
} Rollup will write everything under However, with Nollup (and Adding So it appears that URL-wise, we cannot currently get same result with same config between Rollup + "serve public" and Nollup for |
It's an interesting point, but I don't think doing the same thing with The way I see As far as I can tell, prefixing URLs with the
|
Hu hu. Nice wording. It might actually be a use case for multiple public directories. Or My gut feeling, even knee jerk reaction, is that Webpack is uselessly complicated on this point. I remember having a hard time wrestling with this precise set of options. My intuition is that a simple no-exception rule like "everything relative to the public dir(s)" would be easier to comprehend. That being said, truly I don't know. I really don't have a strong opinion on this... If there is a way to have both Nollup and Rollup behave identically with the same non-franken-hackish config, I'm happy with that. I can take it as the "proper" way. I had overlooked the config you're suggesting, but for me it fits the bill. So in regard to this issue, that is generated URLs, I think I'm all good with the proposed PR, both with I'll need to dig more in the question of dynamic imports, but so far so good. I'll open another issue, if needed. Thanks again for all your help :) |
Released in |
Works like a charm, thanks! (rixo/svelte-template-hot@442e638) Now, in the config, I only need the NOLLUP env variable to prevent firing up the web server. I'm not a big fan that they put the web server in the Rollup config... The config doesn't need the variable anymore because it is now used internally by the plugins to handle the differences, which is made safe by the variable being official :) |
I'm sorry to keep bugging you with all my issues, but I'd really like to bring Nollup to feature parity with Rollup, at least for the official Svelte template and simple cases, and make it the preferred solution for Svelte HMR. I just love Nollup's speed. Sometimes, I wonder if an update has applied because it happened in the time interval while my eyes were jumping from the left side of my screen to the right (editor -> browser)...
So, I've got a problem in my template because I haven't enough control (or maybe understanding) on the URL of the files generated by the bundling.
This problem is the reason why I have this special handling of
output.file
for Nollup. Note that this workaround doesn't work anymore with0.9.0
.Say I have
output.file: 'public/build/bundle.js'
.In versions before
0.9.0
, Nollup will use the full path as URL, e.g.http://localhost:8080/public/build/bundle.js
.In
0.9.0
, it only uses the basename, e.g.http://localhost:8080/bundle.js
.What I really want is
http://localhost:8080/build/bundle.js
. That's what I get if I build this with Rollup and launch a http server from thepublic
directory. The file gets written inpublic/build/bundle.js
, and the server seesbuild/bundle.js
as the URL.So I would expect Nollup with
contentBase: 'public'
to produce the same URL.For illustration, I've hacked something that works for me.
I think reusing
contentBase
is the correct behaviour because, like I said, that's what you get if you use Rollup + a web server. So Nollup, to align with Rollup, would write the "virtual" (in-memory) file topublic/build/bundle.js
; and, if it serves (contentBase) from dirpublic
, then it should see the URL asbuild/bundle.js
. Is this a good idea to change the meaning of an existing variable though?Another question is: what to do with files that are written outside of the public directory? For example, if I have
output.file: 'dist/bundle.js'
, butcontentBase: 'public'
. Hmm. In this case, my implementation just use the full path of the file as URL, because I don't see any other solution.With
output.dir
, I think Nollup's behaviour is aligned with Rollup, as a bundler. However, as server, it makes the assumption that the output dir is also the public dir, which might not hold in every project. I guess most cases can be handled by tweakingentryFileNames
, but I think that these settings should live in Nollup's config, not Rollup's. They are related to serving, not bundling.I'm not too sure what the solution should look like. Should it be based on
contentBase
or some new specific options?The text was updated successfully, but these errors were encountered: