-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[parcel 2] does not minify css imported with bundle-text:
#5755
Comments
It probably has to do something with the parcelrc matching of optimizers for named pipelines, both of these cases aren't minified: // import x from 'bundle-text:./styles.css';
import x from 'url:./styles.css';
console.log(x); body: {
color: red;
color: red;
} |
As I've speculated, this is because if a request has a pipeline, it has to exactly match an entry in the parcelrc. Commenting this out "fixes" it, but the question is how parcelrc matching should behave in general... parcel/packages/core/core/src/ParcelConfig.js Line 386 in 1188e59
|
Can confirm it works. The file is in Wooo-hooooo, minified css here I come :D |
Hey @mischnic dunno if this is the right place to ask, but css imported with
So it basically just returns the string again. Could it be included as a string directly instead? I stumbled upon a script which includes css based on a variable in a config section and the interopDefault wrapping of the string confuses terser (or whatever does the magic) so it no longer removes the css if it isn't needed in that build. When importing it as a normal ts file which exports it like this |
We should probably add a pure comment to the interop call, Terser removes everything here: !(function () {
const css = "body{background:red}";
function $parcel$interopDefault(a) {
return a && a.__esModule ? a.default : a;
}
const $css$interop = /*@__PURE__ */$parcel$interopDefault(css);
// console.log($css$interop);
})(); Would that fix your case? |
That would be amazing! TIL about pure comments |
-> #5765 |
Is there something I can put in my parcelrc to work around this bug instead of editing parcel? |
(I haven't tested this) {
"extends": "@parcel/config-default",
"optimizers": {
"bundle-text:*.css": ["@parcel/optimizer-cssnano"]
}
} |
Works beautifully, thanks! |
Shouldn't you use the '...' feature? |
@ProLoser can you elaborate? |
Nevermind @mischnic solution is better, I was thinking maybe |
Yeah. You still shouldn't have to actually list out all pipelines in the optimizers object though... |
@devongovett Idk what pipelines and optimizers are but sounds good. Once it's out I will test it and see if it works. BTW could you update SWC like this but to the newest version? That should fix #6356 |
🐛 bug report
When importing css as string into javascript with
bundle-text:
as described here the css does not get processed at all.🎛 Configuration (.babelrc, package.json, cli command)
Cli command:
npm run build
Please see attached .zip file for the rest.
🤔 Expected Behavior
The inlined css code should be minified and look like this:
😯 Current Behavior
The inlined css code looks just like before.
💁 Possible Solution
Process the css
🔦 Context
#5751
💻 Code Sample
parcel-no-css-postpro.zip
🌍 Your Environment
The text was updated successfully, but these errors were encountered: