Bundling @import'ed CSS files into single file #51
Replies: 1 comment 4 replies
-
Hallo Lukas, using @import in pure CSS is not deprecated but nobody use it. It's very very The Pug plugin deliberately does not support this dead feature because it is difficult to implement the resolving of imported CSS and never used by anyone. If you will use separate CSS files, then use For example, you has a CSS @import 'button.css';
h1 {
color: red;
} then change the extension to @use 'path/to/button.css';
h1 {
color: red;
} The path for included file via But, you can pass throw the unhandled {
test: /.(css)$/i,
use: [
{
loader: 'css-loader',
options: {
import: false,
},
},
],
}, Note: in this case imported CSS file must be manually copied to Please try this trick. P.S. I will update README with this info. |
Beta Was this translation helpful? Give feedback.
-
First off, thank you for this great plugin. I'm glad to finally switch away from the outdated
pug-loader
.One use case that doesn't seem to be supported, however, is the combination of
@import
'ed CSS files into a single file. Splitting these files up may happen for different reasons, e.g. separating semantically distinct chunks (styling navbar/content/footer) for easier maintainability, or to reuse sections in multiple entry points. However, when bundling, I'd prefer to resolve the@import
statements into a single file. Especially for multiple small CSS files, this improves loading times by reducing the number of requests necessary. The bundled file may also yield a better compression ratio when hosting gzip'ed files.Previously, I've been using
mini-css-extract-plugin
, which provided the behavior described above. Aspug-plugin
claims to be a replacement, I'd expect there to be a way to imitate this. However, the best I could achieve is outputting all CSS files separately (which may be unintended, see below).When trying to use
@import
-rules, an error is thrown. Is this based on a deliberate decision to not support this CSS feature, or is it just not yet implemented? If this is working as intended, it would be great to clearly state this in theREADME.md
. I've only found a note about using@use
instead of@import
in SASS, however, I'm using plain CSS (where@import
isn't deprecated).config/error inconsistencies
There seems to be an unintended way of circumventing the
@import
-error. Again, if this is indeed intended, it would be great if this behaviour was documented somewhere.first case: css-loader options configured as requested
This results in only the main CSS file being emitted, with unhandled
@import
rules. This fails at runtime, as the required sub files aren't emitted.second case: empty css-loader options
As expected, this fails at build time with the following error:
third case: no css-loader options
When not providing any options to
css-loader
,pug-plugin
handles the imported files without issue. Both the main file and the sub files are emitted. While this configuration works, this behavior does not seem to be intended, as it is fairly surprising that providing an empty config differs from providing no config.Beta Was this translation helpful? Give feedback.
All reactions