-
Notifications
You must be signed in to change notification settings - Fork 87
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
Use postcss-modules generated css repeated #32
Comments
I'm getting this same issue. I'm using gulp instead of webpack. |
Got the same issue today. But for me after disabling autoreset plugin issue disappeared. Could you post what plugins in which order are you using @lukelarsen @imseanpan? |
I'm glad someone responded. I'm using gulp to process everything. We are also using the Aurelia framework. Here is the file that does the css stuff:
Here is a sample of how the css files are added
I don't see the |
i have the same issue, duplicated css classes. |
I've just encountered the same issue with a build process that I configured that uses I don't think there is a problem with Here's why: tools such as But when you pipe it through To resolve this, you can simply use Here's how with // gulpfile.js
import gulp from 'gulp';
import postcss from 'gulp-postcss';
import postcssrc from 'postcss-load-config';
gulp.task('styles', () => {
const { plugins, options } = await postcssrc();
const { plugins: minPlugins, options: minOptions } =
await postcssrc({ minifier: true });
return gulp.src(['src/**/*.css'])
.pipe(sourcemaps.init())
.pipe(postcss(plugins, options))
.pipe(concat('styles.css'))
.pipe(postcss(minPlugins, minOptions))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist/public'));
}); // postcss.config.js
module.exports = (ctx) => {
const plugins = [];
if (ctx.minifier) {
plugins.push(
require('cssnano')({})
);
} else {
plugins.push(
require('postcss-import')(),
require('postcss-cssnext')(),
require('postcss-modules')()
);
}
return { plugins };
}; |
Thanks for the comments. In my build I don't think cssnano will work. I'm using Aurelia JS and while everything is working properly it outputs the css for each component in its own <style> tag. cssnano is run on each one of those so it doesn't see the duplicates. :( |
Tiny repro here : https://github.com/AlexGalays/repro-webpack-cssloader Expected: Only two classes in the extracted Looks like the trigger is for a className to be imported both in JS (to be used as a className string) and CSS (via |
@AlexGalays For now postcss-loader and cssnano will probably help. |
@plesiecki Thanks; I had to use optimize-css-assets-webpack-plugin to make it work in my setup, but it should be equivalent. |
This behavior seems to be fundamentally different from the original design intention, which seems to have been that |
HI,
Q1 I want to use postcss-modules compile my css files, but out of the css generated duplicate.
1. common.css
.row { width : 100%; height : 100px; margin : 0; padding : 0; background-color : #000000; }
2. subCommon.css
.row { composes : row from './components.css'; background-color : #ff0430; }
3. webpack config
{ test : /\.css$/, loader: ExtractTextPlugin.extract("style-loader", ["css-loader?postcss-modules&importLoaders=1&sourceMap", "postcss-loader?parser=postcss-scss"]) }
4. postcss-modules config
postcss: function () { return [ psmodules({ generateScopedName: '[local]_[hash:base64:8]', getJSON : function (cssFileName, json) {} }), // cssnano(nanoConfig), ];
5 Compiled main.css file
.row_3hpoIFeb { width : 100%; height : 2.66667rem; margin : 0; padding : 0; background-color : #000000; } .row_3hpoIFeb { width : 100%; height : 2.66667rem; margin : 0; padding : 0; background-color : #000000; } .row_3D79gLaJ { background-color : #ff0430; }
common.css the row => [row_3hpoIFeb] is compiled twice!
Q2 Postcss-modules and cssnano can not be used together, compile exception!?
The text was updated successfully, but these errors were encountered: