-
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
Output dir, public dir, and URLs #84
Comments
Haven't tried running it yet, but will do so shortly, so this is just some initial thoughts which might help in the meantime! The chunks naming collision is a good catch. Will need to sort that one out. As for the other two issues, that appears to be working correctly based on the readme doc, when compared to Rollup's Have you tried using Will look into the demo more when I get a chance later this evening. :) |
Yes, indeed, it seems to match with Rollup's This is more a question for the web server side of Nollup than it's bundler side actually. I don't say it should change in the generated bundle (it shouldn't since that's what Rollup does), but the directories should be preserved in the URLs, like with Rollup + web server. With
With Rollup, the file would be accessible at URL Anyway, relying on |
It's worth noting, Rollup watch has an option to not write to the disk: There's a few problems here, and it's mostly down to interpretation and architecture. There's several ways to write a Rollup development server. Before writing Nollup, I used Rollup's That's how I did it, but then someone else can use Rollup entirely differently. Someone might use the Another issue here is the interpretation of
I would expect the files to be served as If a developer is already using the Rollup API with a custom web server, the low-level API is more or less a drop-in replacement and you can generate quick dev bundles. The web-server though, as there's no precedent, it's more opinionated, but I think there's good reason to believe that basing it on I think the implementation that Nollup has at the moment is correct, and is the best balance for all that makes it easy to integrate with minimal changes, while also maintaining consistency with all other bundler development servers. And so it's not forgotten about, chunking name-collision I'll be looking into! :D |
I'm sorry but I can't get to agree with this. To me it seems that the dev server should be producing the same entry points with the same URLs as the "prod" server. Since Considering only the export default [
{
input: 'app1/main.js',
output: { dir: 'dist/app1', format: 'es' }
},
{
input: 'app2/main.js',
output: { dir: 'dist/app2', format: 'es' }
}
] By discarding the To me it still seems that the simplest behaviour to understand and use is for Nollup to pretend to write the same things as Rollup, and pretend to serve from a given fs path. With this we can derive all the same URLs for dev and prod, and if there are naming conflicts that would be because they exist in the prod setup as well. That being said, there might be something that I don't get in this dev server approach... But the required change to support the ISO write workflow in the |
I'm okay with supporting an option for this behaviour, but the problem is that the behaviour is still very ambiguous as to how it should behave with
What would be the result for when |
With Then, the URL would be produced by trimming the An additional option would be needed (e.g. |
I'm not sure reusing A suggestion here, expanding upon
This would say to follow a full write flow, but when serving content, serve from this directory. Would something like this work? This would allow |
Yes, I think it would work. The value of the Reusing |
Another question here for |
I would say no.
Plugins would expect the files to actually exist on FS and, indeed, that could go awry. This hook not being called is part of the normal Rollup workflow, when using From a theoretical point of view, I consider the |
#88 Thoughts? |
@rixo Continuing the discussion with it here. Not sure I understand the issue with generating the manifests. Virtual write shouldn't affect any plugins. How are the manifests being created? Any reference links? |
Regarding the discussion before Sapper, I'm not so sure it was a genius idea to drop files from the bundle if they fall outside of the "public" dir (got bitten by it already). Actually I now don't think Unfortunately, ideally this option should probably live in Maybe a map FS path => base URL (or URL => path?), for complex situations? Maybe we don't care for now? Now, back to Sapper...
In Routify and Svench, the manifests are created by an external process that watches a specific slice of the src directory (typically something like "pages") and writes a For Sapper, I don't know so much, but I believe it takes For example in Sapper, you end up with some code like this that is fed to the bundler: export const components = [
{
js: () => import("../../../routes/index.svelte"),
css: "__SAPPER_CSS_PLACEHOLDER:index.svelte__"
},
{
js: () => import("../../../routes/about.svelte"),
css: "__SAPPER_CSS_PLACEHOLDER:about.svelte__"
},
{
js: () => import("../../../routes/blog2/index.svelte"),
css: "__SAPPER_CSS_PLACEHOLDER:blog2/index.svelte__"
},
...
] Anyway, I think I have mischaracterized the problem in my previous comment. The problem really boils down to Nollup's For example, in one of my setup, I have something like this:
output: { dir: `public/build`, format: 'es' }
virtualWrite: 'public',
// this is something else I'd like to discuss, someday...
watch: ['src', '.svench/*', 'node_modules/svench/tmp'],
<script type="module" src="/build/main.js"></script> Now, let's say somewhere in my code I have an import like this: import('./foo.js') Then the dynamic import generated by Nollup will try to fetch the chunk at URL I've managed to fix it in Svench by patching // context.baseUrl also added by the patch
if (context.baseUrl && (entry.isEntry || entry.isDynamicEntry)) {
entry.fileName = (context.baseUrl + '/' + entry.fileName)
} But with Sapper it doesn't work. Guess why? Because it breaks alignment with Rollup, as you've always said! Specifically, Sapper generates the entry script URL (in So... What do you think? |
Web apps running in a URL subdirectory always seem to occur with mind-boggling headaches! D: It sounds like the I'm very reluctant to start adding custom options to Rollup config as well. Because this involves the generated code, we have to look at this from the perspective of calling Here's one thing that I did think of that might work, assume the following option existed in
Like in Webpack, all assets and scripts will only be available if you have that URL prefixed, and dynamic imports will have it prefixed as well. I have a couple of ideas on how I can get this to work, mainly by taking advantage of https://rollupjs.org/guide/en/#renderdynamicimport. I'm thinking the dev middleware could inject a custom plugin that uses that hook to inject the public path. The hook is not implemented yet in Nollup, and I'm not entirely sure how it would work with the dynamic import map but I think it's feasible. What are your thoughts on that option in |
Also worth noting, Webpack doesn't have multiple public paths options (seems to be refusal to implement it and people are using workarounds). So there's no precedent here from what I can tell to take inspiration from. |
Yes, this is Webpack's So, yup I think it would solve the reported problem. I'm all for it. I'm ambivalent about the multi-value array form. I find it clunky but I can think of a better alternative. Postponing the multi value support until a brilliant idea or a real need would be ok with me. I didn't know about this hook. Seems to have a lot of hack potential! If you can get a new hook supported in Nollup in the process, it's all the better.
I think Snowpack's Something similar could probably solve most cases where different publicPath for different output would be desired. Web servers routinely mount different directories / files on specific URLs. I guess that's what would be doing (and trying to replicate in Nollup) an app with this need. I don't have such a use case at hand though, so that remains theoretical for me. |
Just occurred to me, using 😑 I don't think there's any clean way of solving this. Probably will have to bite the bullet and pass a custom property in Rollup config. Going to think about this one more... |
Humour me, does the latest I've noticed that Rollup outputs relative URLS, and that imports resolve relative to the script that imported them, not to the URL, which means they don't need to start with I've pushed a new example |
Yes, it works in Svench. It's the easiest setup, that requires the less patches. Mainly, it's now working without any invasive patch (only surface things, will report...). It's still using dynamic imports & one setup needs I'm trying to hook it into Routify & Sapper as soon as I can (probably tonight). |
Interesting: looking into Routify now... It uses |
Still have to diagnose the cause (or make a clean repro) but apparently, in Routify, Nollup has a hard time swallowing this named export: export const {tree, routes} = buildClientTree(_tree) I get If I rewrite the above line as follow, I do get the expected result: const result = buildClientTree(_tree)
export const tree = result.tree
export const routes = result.routes |
Never knew that was even possible. Can you write that into a separate issue? Need more details on the |
Plugged into Sapper with I'm creating repros for the other issues I've mentioned here. |
Like I've mentioned in the other issue, I've got Nollup to work with Routify. I didn't need the I wasn't able to reproduce this
|
|
I would personally prefer for it not to be included in the current refactor because it would increase the risk of introducing new bugs all while making it harder to find their root cause. |
I can see the problem with the Perhaps the |
Yes, if I remember correctly, the |
So here's a few scenarios to consider: Scenario 1:
Scenario 2:
Scenario 3:
Scenario 4:
Will need to figure out a proposal that works for all of these and more potentially... |
Just thinking about this further, and I'm not sure if there's any right answer at all for The ability to use Nollup out of the box with the "recommended" template of outputting to I'm torn on the "what if it doesn't start with So I think the refactor will proceed as is (assuming there's no other issues). |
Makes sense. Regarding your previous message, I think
The refactor seems good to me. I've had another bug in another pretty exotic rename in chain situation (very corner case, not very important) but, apart from that, everything seems to be humming good. I've got friends at Routify starting to use it on their own too, and I've not been reported any issue for now. Seems solid! |
I'm not sure if I want to tie Only other thing I can think of is to have an obscure option similar to
That's great news! Once it's been tested a bit further, I'll tidy it up for a full release! |
FYI, going to tidy up the Refactor branch in regards to documentation, and aim to have a full release this week. :) |
Released in |
So, this is a bit of a follow up to #56.
I am encountering issues with URLs in several projects I'm trying to Nollupize. I've identified 3 causes:
output.dir
are discarded from URL, which defers from Rollupdist
andpublic
folder, and I need URLs from Nollup to be adjusted accordinglyI've created a repo to illustrate and help diagnostic the issues: https://github.com/rixo/nollup-test-case-output-dir
The problems are described in detail in the readme.
I've gone fancy and used a test runner that is not yet very stable, especially with Windows... Let me know if it doesn't work for you, I'll try to simplify the setup.
The text was updated successfully, but these errors were encountered: