Skip to content

Commit 8cc36e0

Browse files
committed
bug #108 Fixing a bug where @import CSS files were not put through the autoprexer (weaverryan)
This PR was merged into the master branch. Discussion ---------- Fixing a bug where @import CSS files were not put through the autoprexer Fixes #98 By default, when you use `@import`, loaders are not applied. This fixes that: using the postcss-loader when it's used. The functional test proves the fix. Commits ------- 35c7e6d Fixing a bug where @import CSS files were not put through the autoprefixer
2 parents f8fa5c0 + 35c7e6d commit 8cc36e0

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

fixtures/css/imports_autoprefixer.css

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "autoprefixer_test.css";

lib/loaders/css.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,24 @@ const loaderFeatures = require('../loader-features');
1818
*/
1919
module.exports = {
2020
getLoaders(webpackConfig, skipPostCssLoader) {
21+
const usePostCssLoader = webpackConfig.usePostCssLoader && !skipPostCssLoader;
22+
2123
const cssLoaders = [
2224
{
2325
loader: 'css-loader',
2426
options: {
2527
minimize: webpackConfig.isProduction(),
26-
sourceMap: webpackConfig.useSourceMaps
28+
sourceMap: webpackConfig.useSourceMaps,
29+
// when using @import, how many loaders *before* css-loader should
30+
// be applied to those imports? This defaults to 0. When postcss-loader
31+
// is used, we set it to 1, so that postcss-loader is applied
32+
// to @import resources.
33+
importLoaders: usePostCssLoader ? 1 : 0
2734
}
2835
},
2936
];
3037

31-
if (webpackConfig.usePostCssLoader && !skipPostCssLoader) {
38+
if (usePostCssLoader) {
3239
loaderFeatures.ensureLoaderPackagesExist('postcss');
3340

3441
cssLoaders.push({

test/functional.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,9 @@ module.exports = {
483483

484484
const config = testSetup.createWebpackConfig(appDir, 'www/build', 'dev');
485485
config.setPublicPath('/build');
486-
config.addStyleEntry('styles', ['./css/autoprefixer_test.css']);
486+
// load a file that @import's another file, so that we can
487+
// test that @import resources are parsed through postcss
488+
config.addStyleEntry('styles', ['./css/imports_autoprefixer.css']);
487489
config.enablePostCssLoader();
488490

489491
testSetup.runWebpack(config, (webpackAssert) => {

0 commit comments

Comments
 (0)