-
Notifications
You must be signed in to change notification settings - Fork 115
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
Duplicated content when @importing the same dependency from different CSS files #316
Comments
I think this is webpack-related; @michael-ciniawsky would know better. |
Remove
entry.js import './styles/vendor.css'
import a from './a/a.js'
import b from './b/b.js'
... a.js import './a.css'
... a.css @import './styles/a-1.css';
... Wont't fix for |
Closing as per @michael-ciniawsky |
That's quite a problem because without postcss-import there's no way to use variables (postcss-custom-properties) or mixins (postcss-mixins) from That's true, Maybe if I explained the case, some things would become clearer: The goalCKEditor 5 is an extremely modular text editor. It consists of many packages which (among many other things) provide views (ES6 classes) to create the UI. In other words: it's a framework. A developer can compile an editor which uses only:
while the packages ( Each view brings some HTML+JS to the application. E.g. Our goal is to make sure that when a view is imported in the application, it comes with the necessary CSS. And if the view is not used, the styles should not be in the webpack's output. It's all about making the builds of the editor optimal. The problemThe import '../../theme/components/button.css';
export default class ButtonView extends View {} and so does import '../../theme/components/toolbar.css';
export default class ToolbarView extends View {} The problem is that both components use some pre–defined colors in variables (and mixins, but let's focus on colors to keep things simple): colors.css :root {
--ck-color-background: white;
} button.css: @import "../helpers/colors";
.ck-button {
background: var(--ck-color-background);
} toolbar.css: @import "../helpers/colors";
.ck-toolbar {
background: var(--ck-color-background);
} We decided to migrate the project from SASS to PostCSS because it totally failed when it came to handling imports. I.e. the We figured out that In fact, the problem we face here is the last one we have to finish the migration. What we expect is :root {
--ck-color-background: white;
}
.ck-button {
background: var(--ck-color-background);
}
.ck-toolbar {
background: var(--ck-color-background);
} but what we see is :root {
--ck-color-background: white;
}
.ck-button {
background: var(--ck-color-background);
}
:root {
--ck-color-background: white;
}
.ck-toolbar {
background: var(--ck-color-background);
} and it will totally bloat our codebase because the project is huge and the will be tons of variable declarations like this repeated hundreds of times. We're developing a library and the size really matters. See, using Perhaps we missed something important or obvious here? Maybe there's some way to aggregate/concatenate (???) styles on the fly with It's a stalemate for us and any help would be appreciated. |
Via
Theming is complicated with
|
Because this creates a lot of duplication when importing css variables files in other css files which are then imported via js. See: - postcss/postcss-import#316 - postcss/postcss-import#294 - postcss/postcss-import#224
Because this creates a lot of duplication when importing css variables files in other css files which are then imported via js. See: - postcss/postcss-import#316 - postcss/postcss-import#294 - postcss/postcss-import#224
I'm going to try the |
It's been a while. Is this still an issue? |
Yes, unfortunately it is still an issue as I've just encountered this problem today and can't find any solution. |
This is also a problem with plain CSS Given the OP's example,
native CSS will behave exactly as .shared {}
.foo {}
.shared {}
.bar {} This is not only bad because of duplication, but the second occurrence of For reference, this WICG thread describes the native CSS issue. This prevents any intuitive sense of code re-use in CSS. |
… in order to avoid issues with @import. The problem is described in the following places: https://discourse.wicg.io/t/importing-css-only-once/1933 postcss/postcss-import#316
is there any solution to this? im close to giving up entirely with postcss |
This issue is a long thread of potentially unrelated problems; I'm locking this to prevent further noise. postcss-import will always follow native CSS behavior; if there's a problem otherwise, please open a new issue. |
Setup
JS
app.js
foo.js
bar.js
CSS
foo.css
bar.css
shared.css
PostCSS, Webpack
postcss.config.js
webpack.config.js
Expected
Actual
The problem is that
shared.css
has been imported twice.Note that the duplicate (
import '../css/foo.css';
) inbar.js
has been detected and skipped correctly (single.foo{}
in the output). It's all about@import "./shared.css";
.The text was updated successfully, but these errors were encountered: