Code Monkey home page Code Monkey logo

Comments (6)

kellymears avatar kellymears commented on July 22, 2024 2

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.

from bud.

kellymears avatar kellymears commented on July 22, 2024 2

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.

talss89 avatar talss89 commented on July 22, 2024 2

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.

strarsis avatar strarsis commented on July 22, 2024 1

Yes, with the bud plugin everything works great out of the box.

from bud.

talss89 avatar talss89 commented on July 22, 2024

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.

kellymears avatar kellymears commented on July 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.