-
-
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
🐛CSS Importing effectively broken #1165
Comments
What about gathering variables using postcss and applying them down the tree? Gathering in |
@DeMoorJasper I'm not sure, another thing i thought about was doing running |
My hack of commenting out collectDependencies hasn’t introduced any side effects for me (yet).
I did have to set up a separate gulp task to watch for changes in imported css files and touch the css entry file to force it to recompile, but that appears to be a separate issue with Parcel not watching imports.
… On Apr 10, 2018, at 11:06 AM, Jesse Hoyos ***@***.***> wrote:
@DeMoorJasper I'm not sure, another thing i thought about was doing running collectDependencies() inside preTransforms() but i have no idea if that would work.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@irritant I admire your commitment to Parcel but I think at that point it might be easier to just use Gulp as the build tool or even plain Webpack. I have to make that decision myself since unfortunately I cant stop work waiting for this issue gets fixed, Parcel was really great for everything else though. |
If parcel isn't responsible for collecting and parsing the dependencies it doesn't know about it resulting in the manual force recompiling. |
.postcssrc.js const variables = {
'--red': '#12345'
}
module.exports = {
plugins: [
require('postcss-custom-properties')({
variables // <= Available to all modules (@imports)
})
]
}
|
@DeMoorJasper No sass, just a simple postcss.confg.js which is only running |
Parcel processes each CSS file independently, which is why your imported variables aren't being replaced. This strategy makes it faster since we can process each CSS file in parallel rather than one huge concatenated at the end. Seems like CSS always allowed each file to be processed independently until variables were added. I can't think of another case where this is a problem. Perhaps we could detect if postcss variables are being used and enable a post-processing step in the CSSPackager to replace variables. Other postcss plugins would still be applied to each individual file. This would require re-parsing the concatenated css though, which would be sub-optimal. |
Actually that probably wouldn't work since other postcss plugins may rely on the variable already being replaced earlier. e.g. a plugin that inlines We definitely don't want to do all postcss processing on the final concatenated source though. hmm... |
@devongovett What is the reason we dont want postcss processing on the final concatenated file? Is that not how every other tool does this type of stuff? |
@jssee For me, the minor inconvenience of maintaining my fork and running a separate gulp task is worth Parcel's other benefits. My gulp task is:
Piping |
@devongovett any progress on this? |
I recently discovered Parcel and used it from last couple days (it's great!) and I'm also banging my head around CSS issues. Here's my 2 cents, specially after reading @devongovett comment:
Although clever, and desirable, this is not how CSS is generally processed. CSS is not JS and although PostCSS could come close (I don't know enough about PostCSS), certainly LESS is not. AFAIK CSS @background-color: red;
body {
background: @background-color;
}
@background-color: blue; What would the processed In other words, although the snippet does not have any Both LESS and SASS require processing the whole thing anyway. LESS for obvious reasons: it requires a 2-pass compilation. But as a general rule of thumb CSS processors never had the notion of "scopes" so importing a CSS file does not open a new "scope" or whatever. It is expected for a |
not sure if it helps anyone but I have published a small postcss plugin as a temporary work around for my project:
and in the pcss files use then basically it hides it from parcel importing and will substitute the rule with the file contents before other plugins are run. This is just a temporary solution until this bug is solved. Source code under MIT: https://github.com/mendrik/postcss-parcel-import |
my solution was to build in two steps. "scripts": {
"build": "yarn run parcel && yarn run postcss",
"postcss": "postcss -c scripts/postcss.config.js --replace src/css/app.css -o dist/*.css",
"parcel": "parcel build index.html"
} and run |
I'm not sure if this is a stupid question or not but if I'm using scss only and in one file (root.scss), I do :
and then in another file (app.scss) I do :
...will this trigger the same undefined error under parcel ? (thinking of switching to parcel) |
Going on what @michael-ciniawsky said, this works: variables.css :root {
--distancer: 30px;
} button.css .button {
padding: var(--distancer);
} .postcssrc {
"modules": true,
"plugins": {
"postcss-custom-properties": {
"preserve": false,
"importFrom": "src/styles/variables.css"
}
}
} |
Having similar issues with postcss-extend, when referencing from another file: base.pcss index.pcss The example above does not render an error nor populate the body with red color. The idea of rendering every file individually does not make sense to me, as this should all be possible with postcss |
i'm also facing a similar issue. i'd like to use |
The example code in the issue description works correctly with the current Parcel: :root {
--varColor: #639;
}body {
background-color: var(--varColor);
} |
@cmnstmntmn you can get past that by adding |
One issue is that, with this change, Parcel doesn't know anything about the dependencies of a CSS file, and so HMR (and caching) for these doesn't work anymore. |
This comment is only about a workaround. Otherwise ignore it. Having tried the solutions above I found that many only worked sometimes. For me in particular what was broken were my
A note about my double
For whatever reason I need to do both of these. And no, they cannot be the same file. At least not in my testing. For completeness here is my
Here is some of my
|
This answer from @andreidcm worked super well for me! The difference was explicitly passing |
any update on this issue with tailwindcss and @import ? |
For some reason, when using `@import "reset.css"` in a CSS file, Parcel doesn't throw an error but then when you load the page and inspect the generated CSS file, none of the reset code appears there. Strangely, this does work just fine for the normalize.css package, but not reset.css. I tried a few different ways to solve this problem. It's a known fact that [CSS importing is broken in Parcel 1][1], but this bug doesn't seem to be related. Eventually I gave up and we're just vendoring reset.css now. While I was at it I rearranged some of the files. Unfortunately I couldn't organize Elm files into their own folder, but alas. [1]: parcel-bundler/parcel#1165
This is already fixed in Parcel 2 (apart from a cache invalidation bug: #3708) |
The CSS spec requires By processing files independently, the The workaround for now is something like this: import './parcel-fix.scss' // Manually combine all your @import statements here
import '@fortawesome/fontawesome-free/scss/fontawesome.scss'
import 'semantic-ui-css/semantic.min.css'
import './app.scss' |
I'm getting this with even the simplest of setups without css vars, imports etc. Tested with stable and next.
|
Found a counterintuitive fix for working with Tailwind (CC @aguilera51284) |
Experiencing this with Parcel too. |
I have the same problem, with tailwindcss and |
Going to close since this is working in Parcel 2. |
The way Parcel's CSS import is currently being implemented broken. There are several issues related to this problem. Basically, Parcel is applying postcss transforms before concatenating the CSS, this means that any CSS that gets imported is not being transformed properly. This breaks functionality and won't allow you to use basic features like css-variables if they are being imported anywhere.
related to this:
#609
#593
#329
🤔 Expected Behavior
I should be able to declare variables in one file and use them in another via
@import
without gettingundefined
errors😯 Current Behavior
Parcel is not transforming variables that are in imported css files.
💁 Possible Solution
Concatenate the CSS files (i.e. perform import) before applying transforms. Or let users use the
postcss-import
plugin from their own config to get things working properly.@irritant came up with a patch that was as simply commenting out the import gathering during the
collectDependencies()
process, this should perhaps be the default until something is figured out.💻 Code Sample
other.css
input.css
output.css
some more examples can also be found in #329
The text was updated successfully, but these errors were encountered: