mirror of
https://github.com/nuxt/nuxt.git
synced 2025-03-09 03:03:18 +00:00
support postcss.config.js
This commit is contained in:
parent
f24d41e52b
commit
c9def711fa
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user