Giter VIP home page Giter VIP logo

Comments (9)

phaistonian avatar phaistonian commented on May 28, 2024 1

The following snippet illustrated the way I do it.

Works like a charm, but it's far from ideal -- I am guessing :)

In any case, MutationObserver is the way to do it in my case, however since this is not supported by legacy systems, one has to deal with the DOM events too.

Perhaps, "this" could point somewhere :)

import throttle from 'throttleit';

let observer;

function loaded () {
  setTimeout(() => {
    const myEvent = new CustomEvent('webpackReady');
    window.dispatchEvent(myEvent);

    window.webpackIsLoaded = true;
  }, 500);

  // Just once, please
  observer.disconnect();
}

function init () {
  const target = document.head;
  const debouncer = throttle(loaded, 50);
  let isTriggered = false;

  observer = new MutationObserver(mutations => {
    mutations.forEach(mutation => {
      if (isTriggered) {
        return;
      }

      if (mutation.addedNodes.length) {
        isTriggered = true;
        debouncer();
      }
    });
  });

  const config = { characterData: true, childList: true };

  observer.observe(target, config);
}

if (window.ENV.environment === 'local' && window.MutationObserver) {
  init();
} else {
  window.webpackIsLoaded = true;
}

from style-loader.

frenic avatar frenic commented on May 28, 2024

+1

from style-loader.

weotch avatar weotch commented on May 28, 2024

πŸ‘

from style-loader.

elektronik2k5 avatar elektronik2k5 commented on May 28, 2024

+1

from style-loader.

jetpacmonkey avatar jetpacmonkey commented on May 28, 2024

Any possibility that this gets done?

from style-loader.

phaistonian avatar phaistonian commented on May 28, 2024

I did it a while back using MutationObserver.

Nothing fancy, but I'd definitely prefer it would be provided "natively".

from style-loader.

michael-ciniawsky avatar michael-ciniawsky commented on May 28, 2024

@phaistonian can you propose a way to do/add it in style-loader or even better send a PR πŸ˜› ?

from style-loader.

joshwiens avatar joshwiens commented on May 28, 2024

Adds CSS to the DOM by injecting a <style> tag

This feature, regardless of it's utility doesn't belong in style-loader. IMO if the functionality is that useful, a new loader should be created to accomplish this task and then chain them.

from style-loader.

bebraw avatar bebraw commented on May 28, 2024

Yeah, a separate loader would work better.

from style-loader.

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.