├── .gitignore ├── test └── fixture │ ├── css │ └── app.css │ ├── pages │ └── index.vue │ └── nuxt.config.ts ├── .eslintrc ├── renovate.json ├── tsconfig.json ├── package.json ├── LICENSE ├── src └── index.ts ├── CHANGELOG.md └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .nuxt 2 | dist 3 | node_modules 4 | *.log 5 | .idea 6 | -------------------------------------------------------------------------------- /test/fixture/css/app.css: -------------------------------------------------------------------------------- 1 | ::placeholder { 2 | color: gray; 3 | } 4 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "@nuxtjs/eslint-config-typescript" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /test/fixture/pages/index.vue: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "@nuxtjs" 4 | ], 5 | "ignoreDeps": [ 6 | "postcss-loader" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /test/fixture/nuxt.config.ts: -------------------------------------------------------------------------------- 1 | import nuxtpostcss8 from '../../src' 2 | 3 | export default { 4 | buildModules: [ 5 | nuxtpostcss8 6 | ], 7 | css: [ 8 | '~/css/app.css' 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "module": "ESNext", 5 | "moduleResolution": "Node", 6 | "resolveJsonModule": true, 7 | "allowSyntheticDefaultImports": true, 8 | "strict": false, 9 | "types": [ 10 | "node", 11 | "jest" 12 | ] 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@nuxt/postcss8", 3 | "version": "1.1.3", 4 | "repository": "nuxt/postcss8", 5 | "license": "MIT", 6 | "main": "./dist/index.js", 7 | "files": [ 8 | "dist" 9 | ], 10 | "scripts": { 11 | "build": "siroc build", 12 | "prepublishOnly": "yarn build", 13 | "dev": "nuxt dev test/fixture", 14 | "lint": "eslint --ext .ts .", 15 | "release": "yarn test && standard-version && git push --follow-tags && npm publish", 16 | "test": "yarn lint" 17 | }, 18 | "dependencies": { 19 | "autoprefixer": "^10.4.4", 20 | "css-loader": "^6.7.1", 21 | "defu": "^6.0.0", 22 | "postcss": "^8.4.12", 23 | "postcss-import": "^14.1.0", 24 | "postcss-loader": "^4.2.0", 25 | "postcss-url": "^10.1.3", 26 | "semver": "^7.3.7" 27 | }, 28 | "devDependencies": { 29 | "@nuxtjs/eslint-config-typescript": "^9.0.0", 30 | "eslint": "^8.13.0", 31 | "nuxt": "^2.15.8", 32 | "siroc": "^0.16.0", 33 | "standard-version": "^9.3.2" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Nuxt Team 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { resolve } from 'path' 2 | import { satisfies } from 'semver' 3 | import defu from 'defu' 4 | import { name, version } from '../package.json' 5 | 6 | function postcss8Module () { 7 | const { nuxt } = this 8 | const nuxtVersion = (nuxt.constructor.version || '0.0.0').split('-')[0] 9 | const expectedVersion = '>=2.15.3' 10 | if (!satisfies(nuxtVersion, expectedVersion)) { 11 | throw new Error(`postcss@8 is not compatible with current version of nuxt (${nuxtVersion}). Expected: ${expectedVersion}`) 12 | } 13 | 14 | const moveToLast = (arr, item) => { 15 | if (!arr.includes(item)) { return arr } 16 | return arr.filter(el => el !== item).concat(item) 17 | } 18 | const moveToFirst = (arr, item) => { 19 | if (!arr.includes(item)) { return arr } 20 | return [item].concat(arr.filter(el => el !== item)) 21 | } 22 | nuxt.options.build.postcss = defu(nuxt.options.build.postcss, { 23 | plugins: { 24 | autoprefixer: {} 25 | }, 26 | order (names) { 27 | names = moveToFirst(names, 'postcss-url') 28 | names = moveToFirst(names, 'postcss-import') 29 | names = moveToLast(names, 'autoprefixer') 30 | names = moveToLast(names, 'postcss-preset-env') 31 | names = moveToLast(names, 'cssnano') 32 | return names 33 | } 34 | }) 35 | 36 | const pkgDir = resolve(__dirname, '..') 37 | // @ts-ignore 38 | global.__NUXT_PATHS__ = (global.__NUXT_PATHS__ || []).concat(pkgDir) 39 | // @ts-ignore 40 | global.__NUXT_PREPATHS__ = (global.__NUXT_PREPATHS__ || []).concat(pkgDir) 41 | } 42 | 43 | postcss8Module.meta = { 44 | name, 45 | version 46 | } 47 | 48 | export default postcss8Module 49 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. 4 | 5 | ### [1.1.3](https://github.com/nuxt/postcss8/compare/v1.1.2...v1.1.3) (2021-03-10) 6 | 7 | ### [1.1.2](https://github.com/pi0/nuxt-postcss8/compare/v1.1.1...v1.1.2) (2021-03-10) 8 | 9 | 10 | ### Bug Fixes 11 | 12 | * avoid resolving plugins ([b8bc76b](https://github.com/pi0/nuxt-postcss8/commit/b8bc76b589cbda718827d1a4dab07eedbad849e6)) 13 | * throw error for incompatible nuxt version ([def07b0](https://github.com/pi0/nuxt-postcss8/commit/def07b0ca6a62a43ef93c913749b8d17393345cd)) 14 | 15 | ### [1.1.1](https://github.com/pi0/nuxt-postcss8/compare/v1.1.0...v1.1.1) (2021-03-10) 16 | 17 | 18 | ### Bug Fixes 19 | 20 | * improve ordering ([aab942c](https://github.com/pi0/nuxt-postcss8/commit/aab942ccbcd6aae5d5829355b1bde3923b67c488)) 21 | 22 | ## [1.1.0](https://github.com/pi0/nuxt-postcss8/compare/v1.0.4...v1.1.0) (2021-03-10) 23 | 24 | 25 | ### Features 26 | 27 | * autoprefixer and order correction for tailwind ([cdf0ed9](https://github.com/pi0/nuxt-postcss8/commit/cdf0ed934b02281b96140acdc3d2e1d2ff5edb99)) 28 | 29 | ### [1.0.4](https://github.com/pi0/nuxt-postcss8/compare/v1.0.3...v1.0.4) (2021-03-10) 30 | 31 | ### [1.0.3](https://github.com/pi0/nuxt-postcss8/compare/v1.0.2...v1.0.3) (2021-03-05) 32 | 33 | 34 | ### Bug Fixes 35 | 36 | * early return and edge support ([b6b737b](https://github.com/pi0/nuxt-postcss8/commit/b6b737b68c6d8b0cc0e2754162131007fa5ee85f)) 37 | 38 | ### [1.0.2](https://github.com/pi0/nuxt-postcss8/compare/v1.0.1...v1.0.2) (2021-03-05) 39 | 40 | 41 | ### Bug Fixes 42 | 43 | * support prepaths as well and move to module entry ([b0873d0](https://github.com/pi0/nuxt-postcss8/commit/b0873d00f9c3b77020cab0739cc43694641d6c57)) 44 | 45 | ### 1.0.1 (2021-03-05) 46 | 47 | 48 | ### Bug Fixes 49 | 50 | * export meta ([21b25cf](https://github.com/pi0/nuxt-postcss8/commit/21b25cfa816070d231ecf26e0688013ba81dbada)) 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # postcss@8 support for nuxt@2 2 | 3 | [![npm version][npm-version-src]][npm-version-href] 4 | [![npm downloads][npm-downloads-src]][npm-downloads-href] 5 | [![license][license-src]][license-href] 6 | 7 | ## ⚠️ This package is no longer necessary with Nuxt >= 2.16 ⚠️ 8 | 9 | PR [nuxt#9671](https://github.com/nuxt/nuxt/pull/9671) upgraded PostCSS to version 8. 10 | 11 | This module allows opting-in to [postcss@8](https://github.com/postcss/postcss/releases/tag/8.0.0) with nuxt 2 projects. 12 | 13 | - Ensures supported nuxt version is used (`>= 2.15.3 < 2.16.0`) 14 | - Forces to use correct dependencies using `__NUXT_PREPATHS__` 15 | - Will self-adjust integration method based on future nuxt versions 16 | - Use [`autoprefixer`](https://github.com/postcss/autoprefixer) instead of [`postcss-preset-env`](https://github.com/csstools/postcss-preset-env) 17 | 18 | ## Usage 19 | 20 | Install `@nuxt/postcss8` as `devDependency` of project: 21 | 22 | ```sh 23 | yarn add --dev @nuxt/postcss8 24 | # or 25 | npm i -D @nuxt/postcss8 26 | ``` 27 | 28 | Add `@nuxt/postcss8` to `buildModules` in `nuxt.config`: 29 | 30 | ```js 31 | // nuxt.config 32 | export default { 33 | buildModules: [ 34 | '@nuxt/postcss8' 35 | ] 36 | } 37 | ``` 38 | 39 | ### For module authors 40 | 41 | If you have a nuxt module that requires postcss@8, install `@nuxt/postcss8` as `dependency` of module: 42 | 43 | ```sh 44 | yarn add postcss@8 @nuxt/postcss8 45 | # or 46 | npm i postcss@8 @nuxt/postcss8 47 | ``` 48 | 49 | Inside module: 50 | ```js 51 | export default async function() { 52 | await this.addModule('@nuxt/postcss8') 53 | } 54 | ``` 55 | 56 | ## 📑 License 57 | 58 | [MIT License](./LICENSE) 59 | 60 | 61 | [npm-version-src]: https://flat.badgen.net/npm/v/@nuxt/postcss8 62 | [npm-version-href]: https://npmjs.com/package/@nuxt/postcss8 63 | [npm-downloads-src]: https://flat.badgen.net/npm/dm/@nuxt/postcss8 64 | [npm-downloads-href]: https://npmjs.com/package/@nuxt/postcss8 65 | [license-src]: https://flat.badgen.net/github/license/nuxt/postcss8 66 | [license-href]: https://npmjs.com/package/@nuxt/postcss8 67 | --------------------------------------------------------------------------------