-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Triggering update from beforeUpdate #143
Comments
Ok, some thoughts:
site.loadAssets([".js"]); //Load the js files
site.process([".js"], (file) => {
// Bundle the code
file.content = esbuildOutput.content;
}); |
BTW, is there any specific reason to use a custom bundler? Have you try the bundler plugin? |
Yeah. The Deno blunder is not even close to good enough for this (to be fair, it's not designed for this). I need inline source map, minification (and keeping top names, because of WebComponents), tree-shaking, backward compatibility js version support, etc. I'll try Asset/process version, I think I tried it before and failed, but I'll report back. |
Ahn, I figured out the problem. esbuild's Deno version is a pain to work with, because it has a "server" even when you explicit asks it not to have one. And the server MUST be stopped, otherwise it hangs. Because site.addEventListener("beforeSave", ev => {
esbuild.stop();
}); and that solves the problem and it seems to correctly update the js bundles when any other js file changes. thanks for the help. |
Well, technically now the bundles are re-running every time anything changes, it seems. |
Yes, this is the expected behavior. |
Hi again, @fserb |
Oh cool. :) Yeah, there are a few issues with the current plugin that we may want to solve:
What I currently do for b is: I have a I'm not sure if the current way Lume handles assets processing supports that. Do you think this is a reasonable request? If so, how could we do it? I could try to do it over the weekend, but I'm not sure even if there's a way to solve either of those things at this point. nit: we also probably want to remove |
Ok, I understand. The reason to rebuild the entire site after any change, instead of only some pages, is because it's very complex to know in advance the pages that will be affected by any file change. For example:
The only way I can think to have this is configuring directly by the user. For example, with an option like
But this option should be configured manually by the user because, as said, it depends on many things like relations between pages, plugins installed, etc. And about the second issue, there's a similar request here #53. But I'd like to avoid globs because it can affects to performance. site.ignore((filename) => isIgnored(filename)); This could be a good solution for complex ignored conditions. Anyway, in your case I think the best solution is just ignore the folder (or rename the folder prefixing it with Btw, can I add your site to the pages of examples? (https://lumeland.github.io/getting-started/examples/) |
@fserb I just pushed some changes in this direction. The idea is the following: You can configure scoped extensions that will be treated independently of the rest of the pages. For example: site.scopedExtensions([".css"], [".js", ".ts"]); Here we are defining two scopes (one for To manage this, there's a new I not sure if this explanation is clear enough, so let me know your thoughts. I'm also open to change the function name if there's a better name. |
This makes sense to me. And it does address the problem. I wonder if it would make more sense to make those scopes more generic. The reason I say this is that the two obvious dependency connection for any file is "my directory or any subdirectory" and "same extension". I know you've been trying to avoid globs for perf reasons on Overall, I keep wondering if extensions is the right abstraction across the board on Lume, or if things would be cleaner and more powerful if everything was a regexp (and extensions and globs are just subset of Regexps). Re: adding the file as an example, sure. I haven't made the site officially public yet, but go ahead. :) |
Ok, fair enough. site.scopedUpdates(
(path) => path.endsWith(".css"), // A scope with all css files
(path) => path.startsWith("/js/"), // A scope with all files inside "js" folder
) And about the use of extensions instead of regexp, I have thought several times in a way to allow to define functions, but it's more complicated that it seems. The truth is that extensions are a very flexible and understandable format because it define which files must be loaded and how they will be processed:
A regexp only returns In short, we need the extensions, even if we use regexp, glob or any other advanced way to load pages. And having the two things (extensions and glob/functions/etc) would make Lume more complicated and confusing (in addition to possible performance issues). I'm not entirely closed to implement that, but I have to think in the best way to do it so they can coexist harmoniously. |
+1 for For the generic conversation. I hope I'm not sounding pushy, I really don't mean to. I was just using the opportunity to think about this a bit. I agree that extensions make the conversion from src to dest obvious, but the way to solve this generically would be to define a new const formats = {
".tmpl.js": {
match: path => path.endsWith('.tmpl.js'),
transform: path => path.slice(0, -8)
},
}; and we could have: site.addExtensionFormat('.png');
site.addFormat("my format", path => path.startsWith('pages/', path => path.slice(6));
site.preprocess(['my format', '.png'], page => ... ); This takes care of the ergonomics problem, as we can use the keys only as identifiers (basically we could do this change without breaking any config files). It still leaves open a priority issue (when more than one format matches). I can think of two solutions here: add an explicit I'm not 100% sure I understood the other point. One thing that could be complicated is recursion. Because maybe treating local files and generated files the same is not good enough and people may need to match only one of the two. I'd see two solutions for this: either create a special location for generated files (files are matched as |
I love to hear good ideas for Lume, so don't worry :) Your idea of the
File extensions can cover all these casuistry with a single api (just prefix the format at the end of the file name) and it works in both directions (you can register anything (loader, processor, etc) for all files of the same extension; and you can assign a extension to a individual file). In addition to that, you don't need to see the code in the Your proposal could work as a low level API to handle this but I see some limitations, for example how to use Anyway, I'll keep thinking about this and open for suggestions. |
I have some js that I bundle with esbuild. Writing a plugin for it, I ended up with something like:
I make sure that all the dependencies are in an ignored dir, and everything works fine.
Now I want to update the main bundle when one of the deps change. I did something like:
This "works", except that this triggers the whole update cycle twice (including all
afterUpdate
events). If instead of doing this, I simply add the files toev.files
, it doesn't work because thebeforeUpdate
ofcore/source
doesn't get called on the new files.So now I'm stuck: there's no way to restart or cancel the current update, and no way to ask source to clean the cache just for this file. What would be a good idea here?
The text was updated successfully, but these errors were encountered: