-
-
Notifications
You must be signed in to change notification settings - Fork 608
inline import duplication #17
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
Comments
For this we need to change the exports of the css-loader from a simple string to a description object/array. Example: /* style.css */
@import "import.css" medium and (media-query);
body { } [
[require.resolve("css!import.css"), "css from import.css", "medium and (media-query)"],
[require.resolve("css!style.css"), "body {}"]
] The style-loader need to handle this new format and keep track of which module id is already attached to the DOM ( + HMR + ref-counted style ). The ExtractTextPlugin need to handle this format, merge duplicate modules and construct a css SourceMap... Lot of changes required... |
Interesting, this could finally enable developers to write truly modular CSS with pre-processors. Currently it's not possible. |
I had this problem too. Having a hard time using webpack to build CSS bundles properly. The dream would be to mirror the ability to generate commons/chunks bundles as with the JS. |
Also consider using the CSS 'module' pattern that is common in npm-land and used in modules like https://github.com/reworkcss/rework-npm. Then this would work with all the existing modules on npm rather than introducing a new syntax. Using |
I'm not sure, but I think the CSS module pattern is already applied. If you're writing @import "my-module";
.some-style {} webpack generates (roughly) module.exports = require("./my-module.css") + ".some-style {}"; The problem is that pre-processors compile everything down to one big chunk. But with LESS's |
That's resolving |
Yes, that would be cool. Currently you need to append Related discussion: webpack-contrib/less-loader#3 |
I have a working prototype for this. Just need to do some more testing before release... It seems like |
This ensures that items with the same id are only added once. i. e. multiple css file and `@import` the same base css file and it's only added once to the DOM. webpack-contrib/css-loader#17
published... Now an This also works with the extract-text-webpack-plugin. It includes modules only once. And it can create CSS SourceMaps... |
Coool @sokra |
great work! I'm using less now. Wondering does less-loader generate css source map and
|
This is great! Thanks Tobias. Only thing that is different from using |
Trying to do the same thing as @necolas |
Working on this, but it requires some refactoring... |
I have a prototype commited (but not published) that should handle this... The ExtractTextPlugin now build up a mirrowed "extracted" chunk tree with modules. This tree goes to the same optimizing steps as the webpack chunk tree. |
0.9.0? I saw it's on npm already. |
The duplication is fixed. |
fix on this issue not solved in 0.9.0? |
I'm still seeing duplicates (both with ExtractTextPlugin generated files, and the vanilla less loader which includes multiple style tags) Is additional configuration required other than the following?
|
When you have multiple |
@jhnns But I am importing the same .scss file, just in different React components. So why can't webpack identify that these are the same .scss files and only inject a Isn't that what it does with the JS imports? If two components import the same dropdown JS plugin, I assume that the plugin code exists only once in the final .js file. But this appears not to be the logic applied when importing styles. I import the .css or .scss for react-selectize in each instance that react-selectize is used. This creates multiple IDENTICAL EDIT: Just read your response here: webpack-contrib/sass-loader#2 and now I understand that this is not webpack's fault and it can't really do anything about it. I guess I'm switching back to doing SASS the traditional way, there just aren't any real benefits to importing per component through JS files and webpack unless you are doing inline styling. |
@mattaningram if different components require the same scss file, the compilation for that specific file should happen only once (because it is based on the actual filename). If that's not the case, I would classify this at a webpack bug (could you create a minimal demo for that if that's the case?) However, whatever happens inside the SCSS file is not transparent to webpack because now SASS is in charge of compiling it to CSS. It just handles all the paths to webpack in order to resolve it. |
While the original issue here is related to sass/less/stylus, a fix/hack/patch for this is to use the If you want to use this in dev, you will have to use a plugin like |
If I
require('sub1.css')
andrequire('sub2.css')
which both@import url("./base.css")
then I'll get rules in bass.css applied twice in my page, which may cause some problem.Any plan to solve this?
The text was updated successfully, but these errors were encountered: