support postcss.config.js

This commit is contained in:
Pooya Parsa 2017-08-15 01:43:08 +04:30
parent f24d41e52b
commit c9def711fa
2 changed files with 19 additions and 5 deletions

View File

@ -18,16 +18,22 @@ export default function styleLoader (ext, loaders = [], isVueLoader = false) {
// https://github.com/postcss/postcss-loader
let postcssLoader
let postcssPlugins = this.options.build.postcss
if (!isVueLoader && Array.isArray(postcssPlugins) && postcssPlugins.length) {
if (!isVueLoader && this.options.build.postcss) {
postcssLoader = {
loader: 'postcss-loader',
options: {
sourceMap: this.options.build.cssSourceMap,
plugins: () => postcssPlugins,
config: {}
sourceMap: this.options.build.cssSourceMap
}
}
if (Array.isArray(this.options.build.postcss)) {
// If array is provided set it as plugins
postcssLoader.options.plugins = this.options.build.postcss
} else if (typeof this.options.build.postcss.path === 'string') {
// If config object detected
postcssLoader.options.config = this.options.build.postcss
} else {
// Just let postcss-loader resolve it's config
}
}
// https://github.com/webpack-contrib/css-loader

View File

@ -48,6 +48,14 @@ export default function Options (_options) {
options.store = true
}
// Prefer postcss.config.js if no explicit option was provided and it exists
if (Array.isArray(options.build.postcss) && options.build.postcss.length === 0) {
if (existsSync(join(options.srcDir, 'postcss.config.js') ||
existsSync(join(options.rootDir, 'postcss.config.js')))) {
options.build.postcss = true
}
}
// Debug errors
if (options.debug === undefined) {
options.debug = options.dev