Skip to content

Commit 24b890e

Browse files
feat!: nuxt3 support (#125)
chore: decrement version for automatic release
1 parent 3a5075e commit 24b890e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+6215
-9726
lines changed

.eslintrc.cjs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
extends: ['@nuxtjs/eslint-config-typescript'],
3+
overrides: [
4+
{
5+
files: ['*.test.ts'],
6+
rules: {
7+
'no-console': 'off'
8+
}
9+
}
10+
]
11+
}

.eslintrc.js

-6
This file was deleted.

.github/workflows/ci.yml

+12-9
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@ name: ci
33
on:
44
push:
55
branches:
6-
- master
6+
- main
77
pull_request:
88
branches:
9-
- master
9+
- main
1010

1111
jobs:
1212
ci:
1313
runs-on: ${{ matrix.os }}
1414

1515
strategy:
1616
matrix:
17-
os: [ubuntu-latest, macos-latest, windows-latest]
18-
node: [10, 12]
17+
os: [ubuntu-latest, macos-latest]
18+
node: [16]
1919

2020
steps:
21-
- uses: actions/setup-node@v1
21+
- uses: actions/setup-node@v3
2222
with:
2323
node-version: ${{ matrix.node }}
2424

2525
- name: checkout
26-
uses: actions/checkout@master
26+
uses: actions/checkout@v3
2727

2828
- name: cache node_modules
29-
uses: actions/cache@v1
29+
uses: actions/cache@v3
3030
with:
3131
path: node_modules
3232
key: ${{ matrix.os }}-node-v${{ matrix.node }}-deps-${{ hashFiles(format('{0}{1}', github.workspace, '/yarn.lock')) }}
@@ -35,11 +35,14 @@ jobs:
3535
if: steps.cache.outputs.cache-hit != 'true'
3636
run: yarn
3737

38+
- name: Prepare environment
39+
run: yarn dev:prepare
40+
3841
- name: Lint
39-
run: yarn lint
42+
run: yarn lint:all
4043

4144
- name: Test
4245
run: yarn test
4346

4447
- name: Coverage
45-
uses: codecov/codecov-action@v1
48+
uses: codecov/codecov-action@v3

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ node_modules
77
.DS_Store
88
coverage
99
dist
10+
.output

.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
yarn lint-staged

.release-it.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"git": {
3+
"commitMessage": "chore: release v${version}"
4+
},
5+
"github": {
6+
"release": true,
7+
"releaseName": "v${version}"
8+
},
9+
"npm": {
10+
"skipChecks": true
11+
},
12+
"plugins": {
13+
"@release-it/conventional-changelog": {
14+
"preset": "conventionalcommits",
15+
"infile": "CHANGELOG.md"
16+
}
17+
}
18+
}

README.md

+28-109
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
## Features
1313

1414
* Remove unneeded CSS with ease
15-
* Webpack or PostCSS mode
16-
* Already comes with mighty default settings
15+
* Sane default settings
1716
* Built on top of [purgecss](https://github.com/FullHuman/purgecss)
18-
* Nuxt 2 (and only Nuxt 2) support
17+
* Nuxt 2 and Nuxt 3 support (Use v1.0.0 for Nuxt2 support for now)
1918
* Fully tested!
2019

2120
## Setup
@@ -26,11 +25,11 @@
2625
yarn add --dev nuxt-purgecss # or npm install --save-dev nuxt-purgecss
2726
```
2827

29-
2. Add `nuxt-purgecss` to the `buildModules` section of `nuxt.config.js`
28+
2. Add `nuxt-purgecss` to the `modules` section of `nuxt.config.{js,ts}`
3029

3130
```js
3231
export default {
33-
buildModules: [
32+
modules: [
3433
// Simple usage
3534
'nuxt-purgecss',
3635

@@ -40,159 +39,79 @@ export default {
4039
}
4140
```
4241

43-
:warning: If you are using Nuxt **< v2.9** you have to install the module as a `dependency` (No `--dev` or `--save-dev` flags) and use `modules` section in `nuxt.config.js` instead of `buildModules`.
42+
:warning: If you are using Nuxt **2**, please use version 1 of the module.
4443

4544
## Options
4645

4746
### Defaults
4847

49-
Before diving into the individual attributes, please have a look [at the default settings](https://github.com/Developmint/nuxt-purgecss/blob/master/lib/utils.js) of the module.
48+
Before diving into the individual attributes, please have a look [at the default settings](https://github.com/Developmint/nuxt-purgecss/blob/main/src/config.ts) of the module.
5049

51-
The defaults will scan all your `.vue` or `.js` components in the common Nuxt folders, as well as checking your `nuxt.config.js` for used classes.
50+
The defaults will scan all your `.vue`, `.js` and `.ts` files in the common Nuxt folders, as well as checking your `nuxt.config.js` (or `.ts`) for used classes.
5251
Furthermore, typical classes (like these needed for transitions, the nuxt link ones or those set when using scoped styles) are whitelisted already.
5352

5453
These settings should be a good foundation for a variety of projects.
5554

56-
### Merging defaults
57-
58-
You can define every option either as function or as static value (primitives, objects, arrays, ...).
59-
if you use a function, the default value will be provided as the first argument.
60-
61-
If you *don't* use a function to define you properties, the module will try to
62-
merge them with the default values. This can be handy for `paths`, `whitelist` and so on because
63-
the defaults are quite sensible. If you don't want to have the defaults include, just use a function.
64-
6555
### Properties in-depth
6656

67-
#### mode
68-
69-
* Type: `String` ('webpack' or 'postcss')
70-
* Default: `postcss`
71-
72-
Defines the mode, PurgeCSS should be used in.
73-
74-
* Webpack mode can only be used with `build.extractCSS: true`
75-
* PostCSS mode can only be used with a `build.postcss` **object** (no array) or default settings
76-
7757
#### enabled
7858

7959
* Type: `Boolean`
80-
* Default: `options.dev === false` (Disabled during `nuxt dev`, enabled otherwise)
60+
* Default: `!nuxt.options.dev` (Disabled during `nuxt dev`, enabled otherwise)
8161

82-
Enables/Disables the module
62+
Enables the module when set to `true`.
8363

8464
#### PurgeCSS options
8565

8666
Please read [the PurgeCSS docs](https://www.purgecss.com/configuration) for information about
8767
PurgeCSS-related information.
8868

89-
Instead of `content` we use `paths` to specify the paths PurgeCSS should look into (explained [here](https://www.purgecss.com/with-webpack#options).
90-
This applies to **both modes**, not only to `webpack mode`.
91-
9269
## Examples
9370

9471
### Default setup
9572

9673
```js
97-
//nuxt.config.js
74+
// nuxt.config.js
9875
export default {
99-
buildModules: [
76+
modules: [
10077
'nuxt-purgecss',
10178
]
10279
}
10380
```
10481

105-
### Override a default value
106-
107-
```js
108-
//nuxt.config.js
109-
export default {
110-
buildModules: [
111-
'nuxt-purgecss',
112-
],
113-
114-
purgeCSS: {
115-
whitelist: () => ['only-this-class'],
116-
}
117-
}
118-
```
119-
120-
### Append a value to the defaults
82+
### Customize options
12183

12284
```js
12385
//nuxt.config.js
12486
export default {
125-
buildModules: [
87+
modules: [
12688
'nuxt-purgecss',
12789
],
12890

129-
purgeCSS: {
130-
whitelist: ['defaults-and-this-class'],
91+
purgecss: {
92+
enabled: true, // Always enable purgecss
93+
safelist: ['my-class'], // Add my-class token to the safelist (e.g. .my-class)
13194
}
13295
}
13396
```
13497

135-
### Override a default value
136-
137-
```js
138-
//nuxt.config.js
139-
export default {
140-
buildModules: [
141-
'nuxt-purgecss',
142-
],
98+
## Caveats
14399

144-
purgeCSS: {
145-
whitelist: (defaultWhitelst) => defaultWhitelst.slice(1),
146-
}
147-
}
148-
```
100+
* Don't forget to add paths to pages and components that are not part the common folders (e.g. third party packages)
101+
* The default generated 500 and 404 pages will be purged by default. Please ensure you have an appropriate error layout
102+
* Do not use the old `>>>` or `::v-deep` syntax. Instead, go for `:deep`
149103

150-
### Use custom extractors
104+
## Migrating from v1.x
151105

152-
Only one extractor can be applied to each file extention.
153-
If you want to apply a custom extractor to the extensions that the default extractor already covers, you have to override the default extractor. This is only possible with the functional notation.
106+
:warning: If you use Nuxt 2, you can't update to v2.x (yet?)
154107

155-
```js
156-
//nuxt.config.js
157-
export default {
158-
buildModules: [
159-
'nuxt-purgecss',
160-
],
161-
162-
purgeCSS: {
163-
extractors: () => [
164-
{
165-
extractor(content) {
166-
return content.match(/[A-z0-9-:\\/]+/g)
167-
},
168-
extensions: ['html', 'vue', 'js']
169-
},
170-
{
171-
extractor(content) {
172-
return content.match(/[A-z0-9-\\/]+/g)
173-
},
174-
extensions: ['vue'] // This will not work, because the above extractor is applied to 'vue' already.
175-
}
176-
]
177-
}
178-
}
179-
```
108+
1. The webpack mode has been removed, as Nuxt 3 supports Vite and webpack. This way, the logic is unified to use the PostCSS plugin of PurgeCSS. There is no `mode` anymore
109+
2. The config merging logic of v1 has been removed in favor of using [`defu`](https://github.com/unjs/defu). Instead of using functions, write your values as usual and they will be merged.
110+
3. PurgeCSS has been bumped from v2.x to v5.x - Please check the current [config options](https://purgecss.com/configuration.html#options)
111+
4. Change the module key has been changed to just `purgecss`.
112+
5. In addition to `enabled`, all purgecss configurations can be written directly into the `purgecss` object.
113+
6. Eventually, check out the playground of the module and the [current defaults]([at the default settings](https://github.com/Developmint/nuxt-purgecss/blob/main/src/config.ts))!
180114

181-
## Migrating from v0.x
182-
183-
1. Review the [**Release Notes**](./CHANGELOG.md) for all changes
184-
2. Bump to 1.x
185-
3. Ensure the plugin is running in the right mode
186-
* If you used the default mode, you have to add `mode: 'webpack'` to your config.
187-
* If you used the `postcss` mode, you can remove the `mode: 'postcss'` line from your config
188-
* If you used this module only with the [Nuxt `tailwind` module](https://github.com/nuxt-community/tailwindcss-module), you don't need to do anything
189-
4. Read about the internal changes of [PurgeCSS 2](https://github.com/fullhuman/purgecss/releases)
190-
5. Update your extractor and change the syntax from a class to a function (see 4.)
191-
6. Unused styles from SFCs are now purged. If you don't want that, whitelist them.
192-
7. The regex for CSS classes changed. This should not be breaking in most cases.
193-
8. The whitelist now includes nuxt link classes (e.g. `nuxt-link-active`). If you whitelisted these before, you can remove them.
194-
9. The whitelist now includes move transition classes. If you whitelisted these before, you can remove them.
195-
10. Test on your staging server (or locally) before deploying!
196115

197116
## License
198117

commitlint.config.js

-5
This file was deleted.

husky.config.js

-7
This file was deleted.

jest.config.js

-5
This file was deleted.

lib/logger.js

-3
This file was deleted.

0 commit comments

Comments
 (0)