Comments (6)
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:
- https://webpack.js.org/api/loaders/#thisadddependency
- https://webpack.js.org/api/loaders/#thisaddmissingdependency
I'll confirm later and will issue a PR if I'm correct.
from bud.
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());
});
});
from bud.
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. 🍻
from bud.
Yes, with the bud
plugin everything works great out of the box.
from bud.
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!
from bud.
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.
from bud.
Related Issues (20)
- [bug] Bud should not ignore exceptions thrown by dependent tooling HOT 3
- [request] Support npm package provenance
- [request] Regenerate theme.json when tailwind.config.js updated HOT 3
- [bug] Error when trying to build the project ! HOT 1
- dev url not working with Lando HOT 1
- [bug] could not import sass: problem running hook booted HOT 4
- [bug] Sass with Tailwind config gives an error HOT 2
- [bug] trellis alias causing bud build to log warning HOT 10
- [bug] [email protected] incompatible with [email protected] HOT 3
- [bug] Install hangs on postinstall @roots/browserslist-config (bud 6.14.*) HOT 12
- [bug] Bud dev slows down and public keeps growing with hot-update files HOT 4
- [repo] can't upgrade to @yarnpkg/builder@^4.0.0 HOT 3
- [question] Building a bud extension - how to register / expose HOT 1
- [question] best practices for versioning extensions HOT 6
- [bug] When using external IP from another device, styles are unaccessable HOT 3
- [bug] @import'ed tailwind CSS does not invalidate the cache after error with @layer HOT 2
- [bug] using @apply and #{!important} in sage with bud HOT 1
- [bug] `roots` is not defined when using eslint-config HOT 1
- [bug] importing a plugin makes @roots/bud-tailwindcss fail HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bud.