diff --git a/fixtures/css/imports_autoprefixer.css b/fixtures/css/imports_autoprefixer.css new file mode 100644 index 00000000..4dce6d71 --- /dev/null +++ b/fixtures/css/imports_autoprefixer.css @@ -0,0 +1 @@ +@import "autoprefixer_test.css"; \ No newline at end of file diff --git a/lib/loaders/css.js b/lib/loaders/css.js index 002e2e46..231f16d2 100644 --- a/lib/loaders/css.js +++ b/lib/loaders/css.js @@ -18,17 +18,24 @@ const loaderFeatures = require('../loader-features'); */ module.exports = { getLoaders(webpackConfig, skipPostCssLoader) { + const usePostCssLoader = webpackConfig.usePostCssLoader && !skipPostCssLoader; + const cssLoaders = [ { loader: 'css-loader', options: { minimize: webpackConfig.isProduction(), - sourceMap: webpackConfig.useSourceMaps + sourceMap: webpackConfig.useSourceMaps, + // when using @import, how many loaders *before* css-loader should + // be applied to those imports? This defaults to 0. When postcss-loader + // is used, we set it to 1, so that postcss-loader is applied + // to @import resources. + importLoaders: usePostCssLoader ? 1 : 0 } }, ]; - if (webpackConfig.usePostCssLoader && !skipPostCssLoader) { + if (usePostCssLoader) { loaderFeatures.ensureLoaderPackagesExist('postcss'); cssLoaders.push({ diff --git a/test/functional.js b/test/functional.js index 5f839206..8429e0cf 100644 --- a/test/functional.js +++ b/test/functional.js @@ -483,7 +483,9 @@ module.exports = { const config = testSetup.createWebpackConfig(appDir, 'www/build', 'dev'); config.setPublicPath('/build'); - config.addStyleEntry('styles', ['./css/autoprefixer_test.css']); + // load a file that @import's another file, so that we can + // test that @import resources are parsed through postcss + config.addStyleEntry('styles', ['./css/imports_autoprefixer.css']); config.enablePostCssLoader(); testSetup.runWebpack(config, (webpackAssert) => {