Skip to content

Commit

Permalink
update to @nuxt/postcss8
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Mar 10, 2021
1 parent a3767cb commit 4d47977
Show file tree
Hide file tree
Showing 3 changed files with 283 additions and 227 deletions.
35 changes: 13 additions & 22 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,18 @@ module.exports = async function (moduleOptions) {
const configPath = nuxt.resolver.resolveAlias(options.configPath)
const cssPath = nuxt.resolver.resolveAlias(options.cssPath)

// Extend postcss config
// https://tailwindcss.com/docs/using-with-preprocessors#future-css-features
nuxt.options.build.postcss = defu(nuxt.options.build.postcss, {
plugins: {
tailwindcss: {},
'postcss-nested': {},
'postcss-custom-properties': {}
}
})

// Require postcss@8
await this.addModule('nuxt-postcss8')
await this.addModule('@nuxt/postcss8')

// Include CSS file in project css
if (await pathExists(cssPath)) {
Expand Down Expand Up @@ -58,29 +68,10 @@ module.exports = async function (moduleOptions) {
if (!nuxt.options.dev && !process.env.NODE_ENV) {
process.env.NODE_ENV = 'production'
}
/*
** Set PostCSS config
*/
const { postcss } = nuxt.options.build
postcss.plugins = postcss.plugins || {}

// No working at the moment: https://github.com/csstools/postcss-preset-env/issues/191
// postcss.preset.stage = 1 // see https://tailwindcss.com/docs/using-with-preprocessors#future-css-features
// Let's use postcss-nested
postcss.plugins['postcss-nested'] = postcss.plugins['postcss-nested'] || {}

// Let modules extend the tailwind config
// Set tailwindcss config
await nuxt.callHook('tailwindcss:config', tailwindConfig)

/* istanbul ignore if */
if (Array.isArray(postcss.plugins)) {
logger.error('Array syntax for postcss plugins is not supported with v3. Please use the object syntax: https://nuxtjs.org/guides/configuration-glossary/configuration-build#postcss')
} else if (typeof postcss.plugins === 'object') {
postcss.plugins.tailwindcss = tailwindConfig
}

// Add postcss autoprefixer plugin
postcss.plugins.autoprefixer = postcss.plugins.autoprefixer || {}
nuxt.options.build.postcss.plugins.tailwindcss = tailwindConfig

/*
** Expose resolved tailwind config as an alias
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"consola": "^2.15.3",
"defu": "^3.2.2",
"fs-extra": "^9.1.0",
"nuxt-postcss8": "^1.1.1",
"@nuxt/postcss8": "^1.1.3",
"postcss": "^8.2.7",
"postcss-nested": "^5.0.5",
"tailwind-config-viewer": "^1.5.0",
Expand All @@ -58,7 +58,7 @@
"eslint-plugin-vue": "^7.7.0",
"husky": "^5.1.3",
"jest": "^26.6.3",
"nuxt": "^2.15.2",
"nuxt": "^2.15.3",
"standard-version": "^9.1.1"
}
}
Loading

0 comments on commit 4d47977

Please sign in to comment.