-
Background: Lazy CSS Chunks:So I've found, tested, and can implement the pattern from the readme and the import cssUrl from './style-dynamic.scss?url'; I've even extended that for Constructable Stylesheets using (A) Question one: Can we get the CSS source? Constructable stylesheets allow injecting the source. I guess similar to the Question 1: Is there a way to get the CSS source from the above pattern as opposed to just the URL? I was looking for (B) Question two: CSS Chunks from Dynamically imported JS files seem missing...without Our code base is a large SPA, and per route we lazy load files. We split up loads for performance vs the initial render. The first thing I've noticed is that the plugin doesn't seem to generate a CSS chunk for CSS files that are imported inside a JS file loaded via a dynamic import statement, unless the /* file one.js */
import('./two.js');
/* file two.js */
import './style.css'; // does not generate a file
import './style2.css?url'; // does not generate a file
// html-bundler-webpack-plugin does not generate a chunk
// however, using this pattern, it does
import css from './style.css?url'; // does generate a file I considered opening a bug issue report about that, but will wait until I know more about this and run additional tests. Small AsideI also happened to notice, that either by design or coincidence/happenstance, that this seems to NOT work if called: // does not work
const loadStyles = () =>
import('Foo/styles/index.scss');
// nor does this
const loadStyles = () =>
import('Foo/styles/index.scss?url'); This works with the ➔ It would be really great if any css (C) Question three: CSS only imports? At any rate, dynamic CSS and routes was a main use case for us with the This set up allowed us to have a JS file that effectively was dropped and the dependency was just a CSS file. While this isn't our precise use case, it's similar to where things are headed with: With item 2 above, I was hoping to enable |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 11 replies
-
So the other issue I've run into is that so far our Jest tests and Storybook configurations don't care for this syntax: import css from './style.css?url'; This may work with |
Beta Was this translation helpful? Give feedback.
-
Hello @rcherny Question
|
Beta Was this translation helpful? Give feedback.
-
Question
|
Beta Was this translation helpful? Give feedback.
-
Please create an issue by webpack-remove-empty-scripts (last update 2023-08-28) and a small repo with reproducible issue (in some case empty JS file will be not removed) |
Beta Was this translation helpful? Give feedback.
-
Question
|
Beta Was this translation helpful? Give feedback.
-
Really appreciate all the follow up on this. I've had a super hectic week and I'm going on vacation this coming week; so I'll follow up more when I return. Thanks again! |
Beta Was this translation helpful? Give feedback.
Question
C
Currently the plugin doesn't support webpack experimental features, like
experiments.css
.In
cssLoader.js
is only a reserved "placeholder" for the feature that will be released in webpack6
.