Skip to content
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

Import stylesheet as url #6012

Closed
pgarciacamou opened this issue Dec 10, 2018 · 1 comment
Closed

Import stylesheet as url #6012

pgarciacamou opened this issue Dec 10, 2018 · 1 comment

Comments

@pgarciacamou
Copy link

pgarciacamou commented Dec 10, 2018

Is this a bug report?

No. A feature request and proposal.

Feature: allow importing stylesheets as url (e.g. using style-loader/url).

Proposal: Use ":" (colon) at the start, sort of like importing styles from node_modules with a "~". (just an idea, not opposed to hearing other ideas).

Why?

Basically to allow injecting styles into a different DOM.

Barebones example (which explains my usecase):

import stylesUrl from ":path/to/styles[.scss|.sass|.css]";
// ...
var someFrame = (
  <iframe
    initialContent={`
      <!DOCTYPE html>
      <html>
        <head>
          <link href="${stylesUrl}" rel="stylesheet">
        </head>
        <body></body>
      </html>
    `}
  />
);

Which terms did you search for in User Guide?

CSS as URL, stylesheet as URL, SCSS as URL, code splitting, style splitting

Links I read:

What do I do right now?

  1. Hide iframe
  2. On iframe load, use code splitting to use promises
  3. Find the specific stylesheet in the parent DOM
  4. Move stylesheet into iframe
  5. unhide iframe

In sort of pseudocode, it looks like:

// ...
var someRef = React.createRef();
// ...
var someFrame = (
  <iframe {...} ref={someRef} onLoad={() => {
    var doc = someRef.current.contentDocument;
    import("path/to/styles[.scss|.sass|.css]").then(() => {
      var sheet = findStylesheetInParentDOM();
      doc.head.appendChild(sheet);
      unhideIframe();
    });
  }} />
);
@pgarciacamou
Copy link
Author

pgarciacamou commented Dec 11, 2018

I have mixed feelings about this issue because the same can be told about any other type of files (images, scripts, etc...). So, adding style-loader/url would just be a quick fix. I think I'm forced to either eject or solve it in userland for now.

I'm closing this issue because I think it is a subset of #3722 which discusses this exact issue (and more) for different types of files.

@lock lock bot locked and limited conversation to collaborators Jan 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant