mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
Fix auto load postcss.config.js problem
This commit is contained in:
parent
6a1fd757c6
commit
cf693d04a3
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user