Open Moxinilian opened 1 year ago
Please try the nightly version yarn add parcel@nightly
. This is probably already fixed
Unfortunately I could reproduce even using nightly.
{
"name": "testparcel",
"version": "1.0.0",
"license": "MIT",
"private": true,
"dependencies": {
"parcel": "^2.8.4-nightly.0"
},
"@parcel/transformer-css": {
"cssModules": true
}
}
The problem is that test.css
will also become a CSS module, and that then breaks with the <link>
. You should instead remove the global setting and then choose whether specific CSS files should be modules by calling them test.module.css
or test.css
.
I'm not sure I understand. What is the proper way to use a CSS module? Simply renaming the CSS file to test.module.css
and removing the global setting yields the same result.
You cannot use CSS modules in HTML (so <link rel="stylesheet" href="test.css">
).
Instead, remove the global setting and then do
<link rel="stylesheet" href="test.css">
from HTML for non-module CSS and
import * as styles from "./my-component.module.css";
from JS for CSS modules
Right, I see. What is the proper way to do CSS tree shaking when using CSS directly from HTML? I have no CSS-related JavaScript in my projects.
Parcel doesn't have such functionality builtin A PostCSS plugin like https://purgecss.com/plugins/postcss.html might work
Ah I see! Thank you. I think this is still a bug though, as Parcel should at least not crash but emit an error.
Maybe it's been fixed, I'll try to get some time to check.
π bug report
When using CSS modules with Parcel 2.8.3, importing a CSS file from an HTML file causes hitting an unsatisfied assertion.
π Configuration (.babelrc, package.json, cli command)
I managed to create a minimal reproducing example.
package.json
test.html
test.css
Running
yarn parcel build test.html
triggers the issue.π€ Expected Behavior
When running
yarn parcel build test.html
, Parcel should generate bothtest.html
andtest.hash.css
files, with tree shaking and all the nice features of CSS modules applied to the CSS file.π― Current Behavior
Parcel crashes.
I tried removing the assertion out of curiosity, but naturally I only got further errors.
π¦ Context
I was trying to use CSS modules to have tree shaking on my CSS files which tend to be quite unnecessarily large, notably because I include bulma in them.
π Your Environment