Closed strarsis closed 1 year ago
At first glance it looks like the loader needs to declare its dependencies.
For example, this is how bud.js handles extracting @asset
directive in blade source files: https://github.com/roots/bud/blob/main/sources/%40roots/blade-loader/src/asset-loader.cts#L15
The dependency has to be added explicitly otherwise there is no relationship established in the graph (the emitted css is treated as unrelated to the originating source files).
Relevant docs:
I'll confirm later and will issue a PR if I'm correct.
I issued a couple PRs:
The first just adds a single line to the loader which marks it as not supporting caching, which fixes the issue. Maybe kind of brute force but it does the trick. I had trouble with other approaches.
The second is a broader refactor that removes the plugin & store modules in favor of doing all the work in the loader. This is easily cacheable and behaves nominally.
This would be the core of the suggestion:
postcss([extract])
.process(source, { from: parsed.base })
/**
* Extract the editor specific css from the source file
* and emit it as a separate file
*/
.then((extracted) => {
const emitPath = join(`editor`, parsed.base);
this.emitFile(emitPath, extracted.toString(), false);
/**
* Remove the editor specific css from the source file
* and return the result
*/
postcss([remove])
.process(source, { from: parsed.base })
.then((result) => {
callback(null, result.toString());
});
});
Great! I'll have a look at both approaches.
I agree with you, if we can do it all in the loader, then that's the way to go. I'm not sure how 'collecting' rules from multiple modules and emitting one asset will work though.
I really appreciate the time / effort you've put in. Thank you!
I was assuming modules would be concatenated since by this point sass/postcss has already processed everything, so local import declarations will have already been replaced.
If this is not a good assumption (it might not be) then yeah, my approach will be a little lacking as-is.
Thanks for the input on this @strarsis and @kellymears. I've rewritten the plugin as a bud extension using the loader-only approach, and simplified things a lot.
It's at https://github.com/talss89/bud-wp-editor-query
From my POV, happy to close this issue. 🍻
Yes, with the bud
plugin everything works great out of the box.
Agreement
Describe the issue
bud-cache
skips some assets that are emitted by (custom) webpack plugins.Some plugins also use a webpack loader that collects specific information that is later emitted as asset by the plugin. When
bud-cache
caches the assets that would be processed by the webpack loaders (including that one used by the plugin) otherwise, the plugin will get empty information collected by the loader, resulting in missing assets.This would not be an issue when
bud-cache
also cached the emitted assets by that plugin.Expected Behavior
bud-cache
also caches assets emitted by webpack plugins.Actual Behavior
bud-cache
does not cache assets emitted by webpack plugins, resulting in those assets missing in subsequent builds (with cache enabled and no source changed).Steps To Reproduce
A minimal, reproducible sample was created to illustrate the issue (based on Sage 10 +
bud
):$ git clone https://github.com/strarsis/sage10-scss
$ git checkout editor-extract
$ nvm use lts/*
$ npm install
(yarn install
, if preferred)(Initial, uncached build)
$ npm run build
ls public/css/
The filedefault.editor.css
is there.(Subsequent, cached builds)
$ npm run build
ls public/css/
The filedefault.editor.css
is not there anymore.Modify a source file. Re-saving alone will not make it changed for webpack, e.g. add a blank line at the end.
$ npm run build
ls public/css/
The filedefault.editor.css
was created again.Subsequent build:
$ npm run build
ls public/css/
The filedefault.editor.css
is missing again.The
WP Editor Query Plugin
used in this sample uses a loader to collect information which it will then use to emit assets. As no loaders are used in subsequent, cached build runs, the plugin will see no information, hence emitting no assets. This would not cause missing assets whenbud-cache
cached those emitted assets from the uncached/initial run, too.@kellymears: I can add more information or adjust the sample project if needed.
version
6.12.3
Logs
No response
Configuration
Relevant .budfiles
No response