mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
refactor: config Postcss preset and plugins together (#3927)
This commit is contained in:
parent
a3dd7dad6b
commit
61407fec1d
@ -11,10 +11,12 @@ class TailwindExtractor {
|
|||||||
export default {
|
export default {
|
||||||
build: {
|
build: {
|
||||||
extractCSS: true,
|
extractCSS: true,
|
||||||
postcss: [
|
postcss: {
|
||||||
require('tailwindcss')('./tailwind.js'),
|
plugins: {
|
||||||
require('autoprefixer')
|
tailwindcss: path.resolve('./tailwind.js')
|
||||||
],
|
},
|
||||||
|
preset: { autoprefixer: { grid: true } }
|
||||||
|
},
|
||||||
extend(config, { isDev }) {
|
extend(config, { isDev }) {
|
||||||
if (!isDev) {
|
if (!isDev) {
|
||||||
config.plugins.push(
|
config.plugins.push(
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
"nuxt-edge": "latest"
|
"nuxt-edge": "latest"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"autoprefixer": "^7.1.6",
|
|
||||||
"glob-all": "^3.1.0",
|
"glob-all": "^3.1.0",
|
||||||
"purgecss-webpack-plugin": "^0.20.1",
|
"purgecss-webpack-plugin": "^0.20.1",
|
||||||
"tailwindcss": "^0.1.3"
|
"tailwindcss": "^0.1.3"
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
plugins: [
|
|
||||||
require('tailwindcss')('./tailwind.js'),
|
|
||||||
require('autoprefixer')
|
|
||||||
]
|
|
||||||
}
|
|
@ -19,7 +19,6 @@ export default class PostcssConfig {
|
|||||||
|
|
||||||
get defaultConfig() {
|
get defaultConfig() {
|
||||||
return {
|
return {
|
||||||
useConfigFile: false,
|
|
||||||
sourceMap: this.cssSourceMap,
|
sourceMap: this.cssSourceMap,
|
||||||
plugins: {
|
plugins: {
|
||||||
// https://github.com/postcss/postcss-import
|
// https://github.com/postcss/postcss-import
|
||||||
@ -49,7 +48,7 @@ export default class PostcssConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
configFromFile() {
|
searchConfigFile() {
|
||||||
// Search for postCSS config file and use it if exists
|
// Search for postCSS config file and use it if exists
|
||||||
// https://github.com/michael-ciniawsky/postcss-load-config
|
// https://github.com/michael-ciniawsky/postcss-load-config
|
||||||
for (const dir of [this.srcDir, this.rootDir]) {
|
for (const dir of [this.srcDir, this.rootDir]) {
|
||||||
@ -60,15 +59,22 @@ export default class PostcssConfig {
|
|||||||
'.postcssrc.json',
|
'.postcssrc.json',
|
||||||
'.postcssrc.yaml'
|
'.postcssrc.yaml'
|
||||||
]) {
|
]) {
|
||||||
if (fs.existsSync(path.resolve(dir, file))) {
|
const configFile = path.resolve(dir, file)
|
||||||
const postcssConfigPath = path.resolve(dir, file)
|
if (fs.existsSync(configFile)) {
|
||||||
|
return configFile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
configFromFile() {
|
||||||
|
const loaderConfig = (this.postcss && this.postcss.config) || {}
|
||||||
|
loaderConfig.path = loaderConfig.path || this.searchConfigFile()
|
||||||
|
|
||||||
|
if (loaderConfig.path) {
|
||||||
return {
|
return {
|
||||||
sourceMap: this.cssSourceMap,
|
sourceMap: this.cssSourceMap,
|
||||||
config: {
|
config: loaderConfig
|
||||||
path: postcssConfigPath
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,11 +121,14 @@ export default class PostcssConfig {
|
|||||||
this.preset = config.preset
|
this.preset = config.preset
|
||||||
delete config.preset
|
delete config.preset
|
||||||
}
|
}
|
||||||
|
if (Array.isArray(config.plugins)) {
|
||||||
_.defaults(config, this.defaultConfig)
|
_.defaults(config, this.defaultConfig)
|
||||||
|
} else {
|
||||||
|
// Keep the order of default plugins
|
||||||
|
config = _.merge({}, this.defaultConfig, config)
|
||||||
this.loadPlugins(config)
|
this.loadPlugins(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
12
test/fixtures/basic/nuxt.config.js
vendored
12
test/fixtures/basic/nuxt.config.js
vendored
@ -67,13 +67,15 @@ export default {
|
|||||||
],
|
],
|
||||||
build: {
|
build: {
|
||||||
scopeHoisting: true,
|
scopeHoisting: true,
|
||||||
postcss: [
|
postcss: {
|
||||||
require('postcss-preset-env')({
|
preset: {
|
||||||
features: {
|
features: {
|
||||||
'custom-selectors': true
|
'custom-selectors': true
|
||||||
}
|
}
|
||||||
}),
|
},
|
||||||
require('cssnano')
|
plugins: {
|
||||||
]
|
cssnano: {}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user