-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
Inlining CSS via ?inline query is broken when importing CSS/SCSS in JavaScript files #102
Comments
Hello @daltonboll, thank you for the issue report. I try to reproduce issue and find a solution. P.S. Would be nice if you could create a small repo with reproducible issue. |
Note that the If you want to import a CSSStyleSheet object using a query, then use other query, e.g. as in the doc - |
I can reproduce the bug. I will fix it. |
Hi @webdiscus - thanks so much for your helpful reply and for getting back to me so quickly. I started putting together a small test repository for you to take a look at. In doing so, I simplified my code a bit and then was able to get rid of the error that I included in my original post. That error was my fault; the function I was providing to However, as you mentioned in your reply, including the Thanks again! :) |
the v3.17.0 is released. Now you can use the import './style-a.scss?inline'; // the extracted CSS will be injected into HTML
import './style-b.scss'; // the extracted CSS will be saved into separate output file
import './style-c.scss?inline'; // the extracted CSS will be injected into HTML
import './style-d.scss'; // the extracted CSS will be saved into separate output file So the CSS from many files with
Other files will be squashed and saved into separate file:
For example, see please the test case. In the |
This is awesome! I really appreciate your help with all of this. I will surely be recommending this plugin to everyone. :) Thank you so much, and have a wonderful rest of your week! -Dalton |
@daltonboll Thank you for the donation! |
@webdiscus I apologize for bothering you again about this, but I noticed that the CSS imports are still a bit buggy. Specifically, when you use non-inline CSS imports and run webpack in development mode ( The inline CSS imports (e.g., Could you please take another look at this when you get a chance? Thanks in advance! 🙂 |
@daltonboll can you please create small repo with reproducible issue |
@webdiscus sure thing! Here's a small repo I created: https://github.com/daltonboll/debugging-html-bundler-webpack-plugin/tree/master Info about how to reproduce is in the README.md. Thanks for your help! :) |
@daltonboll thank you for the repo. I can reproduce the issue in dev mode und will fix it. |
…another SCSS file via `?inline`, #102
@daltonboll Thank you! |
@webdiscus Awesome! Glad to hear the repo helped. Thank you for fixing this. Have a wonderful weekend! 😊 |
Current behaviour
When I import a .css file or .scss file into a JavaScript file by using an
import
statement likeimport './styles.css?inline'
orimport './styles.css'
, I get an error when I build my project:Expected behaviour
Per this documentation, I would expect that importing the CSS in a JS file with this syntax would automatically inject the CSS into the HTML.
Reproduction Example
I'm using webpack to serve an app with a Spring Boot backend and a React frontend. I'm using babel transpile JS/JSX. The relevant files I'm using are found below:
styles.css (or styles.scss -- I've tried both)
tutorial.js
tutorial.html
webpack.config.js
Environment
Additional context
Note that I realize that I could just have all CSS files be inline injected into the HTML via the global setting described here. However, I want the majority of my CSS files to remain separate. The reason why I'd like to selectively inline CSS files via JS imports is because I want each React component to have its own corresponding CSS/SCSS file.
I could utilize
exportType = css-style-sheet
anddocument.adoptedStyleSheets
in each React component to manually inject the CSS into the html. However, it would definitely be nice to have this done automatically, because that extra step leaves room for errors and is just another thing to remember.The documentation indicates that the behavior I desire should be available, so I'm assuming that this is a bug. Or maybe I have just misconfigured something. 😅
This is an absolutely amazing plugin by the way. It's so powerful, and this CSS import behavior is the last bit of configuration I need in order to have things working just the way I'd like them to. The documentation is also top-notch. Thank you so much for all of your incredible work on this!
Anyway, I would greatly appreciate any help you can provide. Thanks in advance! 😊
The text was updated successfully, but these errors were encountered: