diff --git a/lib/builder/webpack/style-loader.js b/lib/builder/webpack/style-loader.js index 2c4c41ff7e..82a1183cfe 100755 --- a/lib/builder/webpack/style-loader.js +++ b/lib/builder/webpack/style-loader.js @@ -21,11 +21,6 @@ export default function styleLoader (ext, loaders = [], isVueLoader = false) { loader: 'postcss-loader', options: this.options.build.postcss } - if (postcssLoader.options === true) { - postcssLoader.options = { - sourceMap: this.options.build.cssSourceMap - } - } } // https://github.com/webpack-contrib/css-loader diff --git a/lib/common/options.js b/lib/common/options.js index f4e8728d87..2d708f3b23 100755 --- a/lib/common/options.js +++ b/lib/common/options.js @@ -77,51 +77,57 @@ Options.from = function (_options) { // 1. Check if it is explicitly disabled by false value // ... Disable all postcss loaders // 2. Check if any standard source of postcss config exists - // ... Make postcss = true letting loaders find this kind of config + // ... Make postcss = { config: { path } } // 3. Else (Easy Usage) // ... Auto merge it with defaults if (options.build.postcss !== false) { // Detect postcss config existence // https://github.com/michael-ciniawsky/postcss-load-config - let postcssConfigExists = false + let postcssConfigPath for (let dir of [options.srcDir, options.rootDir]) { for (let file of ['postcss.config.js', '.postcssrc.js', '.postcssrc', '.postcssrc.json', '.postcssrc.yaml']) { if (existsSync(resolve(dir, file))) { - postcssConfigExists = true + postcssConfigPath = resolve(dir, file) break } } - if (postcssConfigExists) break + if (postcssConfigPath) break } // Default postcss options - if (postcssConfigExists) { - options.build.postcss = true - } - - // Normalize & Apply default plugins - if (Array.isArray(options.build.postcss)) { - options.build.postcss = { plugins: options.build.postcss } - } - if (isPureObject(options.build.postcss)) { - options.build.postcss = Object.assign({ + if (postcssConfigPath) { + options.build.postcss = { sourceMap: options.build.cssSourceMap, - plugins: { - // https://github.com/postcss/postcss-import - 'postcss-import': { - root: options.rootDir, - path: [ - options.srcDir, - options.rootDir, - options.modulesDir - ] - }, - // https://github.com/postcss/postcss-url - 'postcss-url': {}, - // http://cssnext.io/postcss - 'postcss-cssnext': {} + // https://github.com/postcss/postcss-loader/blob/master/lib/index.js#L79 + config: { + path: postcssConfigPath } - }, options.build.postcss) + } + } else { + // Normalize & Apply default plugins + if (Array.isArray(options.build.postcss)) { + options.build.postcss = { plugins: options.build.postcss } + } + if (isPureObject(options.build.postcss)) { + options.build.postcss = Object.assign({ + sourceMap: options.build.cssSourceMap, + plugins: { + // https://github.com/postcss/postcss-import + 'postcss-import': { + root: options.rootDir, + path: [ + options.srcDir, + options.rootDir, + options.modulesDir + ] + }, + // https://github.com/postcss/postcss-url + 'postcss-url': {}, + // http://cssnext.io/postcss + 'postcss-cssnext': {} + } + }, options.build.postcss) + } } }