Skip to content

Commit c9ea7e3

Browse files
wip
1 parent f9942de commit c9ea7e3

21 files changed

+5851
-4754
lines changed

.eslintrc.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
module.exports = {
22
root: true,
3-
parserOptions: {
4-
parser: 'babel-eslint',
5-
sourceType: 'module'
6-
},
73
extends: [
84
'@nuxtjs'
95
]

.github/workflows/ci.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
ci:
13+
runs-on: ${{ matrix.os }}
14+
15+
strategy:
16+
matrix:
17+
os: [ubuntu-latest, macos-latest, windows-latest]
18+
node: [10, 12]
19+
20+
steps:
21+
- uses: actions/setup-node@v1
22+
with:
23+
node-version: ${{ matrix.node }}
24+
25+
- name: checkout
26+
uses: actions/checkout@master
27+
28+
- name: cache node_modules
29+
uses: actions/cache@v1
30+
with:
31+
path: node_modules
32+
key: ${{ matrix.os }}-node-v${{ matrix.node }}-deps-${{ hashFiles(format('{0}{1}', github.workspace, '/yarn.lock')) }}
33+
34+
- name: Install dependencies
35+
if: steps.cache.outputs.cache-hit != 'true'
36+
run: yarn
37+
38+
- name: Lint
39+
run: yarn lint
40+
41+
- name: Test
42+
run: yarn test
43+
44+
- name: Coverage
45+
uses: codecov/codecov-action@v1

.travis.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

commitlint.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
module.exports = { extends: ['@commitlint/config-conventional'] }
1+
module.exports = {
2+
extends: [
3+
'@commitlint/config-conventional'
4+
]
5+
}

husky.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
hooks: {
3+
'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS',
4+
'pre-commit': 'yarn lint',
5+
'pre-push': 'yarn lint'
6+
}
7+
}

jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
collectCoverage: true,
3+
collectCoverageFrom: ['lib/**/*.js'],
4+
testEnvironment: 'node'
5+
}

lib/logger.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const consola = require('consola')
2+
3+
module.exports = consola.withScope('nuxt:purgecss')

lib/module.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
const path = require('path')
22
const glob = require('glob-all')
33

4-
const logger = require('consola').withScope('nuxt-purgecss')
4+
const logger = require('./logger')
55

66
const MODES = {
77
webpack: 'webpack',
88
postcss: 'postcss'
99
}
1010

11-
export default function nuxtPurgeCss(moduleOptions) {
11+
function nuxtPurgeCss (moduleOptions) {
1212
const { srcDir, purgeCSS = {} } = Object.assign({}, this.options)
1313

1414
Object.assign(purgeCSS, moduleOptions)
1515

1616
logger.start('Loading module')
1717

1818
const defaults = {
19-
mode: MODES.webpack,
19+
mode: MODES.postcss,
2020
enabled: this.options.debug ? false : ({ isDev, isClient }) => (!isDev && isClient),
2121
paths: [
2222
'components/**/*.vue',
@@ -27,14 +27,17 @@ export default function nuxtPurgeCss(moduleOptions) {
2727
styleExtensions: ['.css'],
2828
whitelist: ['body', 'html', 'nuxt-progress', '__nuxt', '__layout'],
2929
whitelistPatterns: [
30-
/.*-(enter|enter-active|enter-to|leave|leave-active|leave-to)/,
31-
/data-v-.*/ // this is needed to prevent removing used scoped css classes
30+
/-(leave|enter|appear)(|-(to|from|active))$/, // Normal transitions
31+
/^nuxt-link(|-exact)-active$/, // Nuxt link classes
32+
/^(?!cursor-move).+-move$/, // Move transitions
33+
/data-v-.*/ // Keep scoped styles
3234
],
3335
whitelistPatternsChildren: [],
3436
extractors: [
3537
{
36-
extractor(content) {
37-
return content.match(/[\w-.:/]+(?<!:)/g) || []
38+
extractor: (content) => {
39+
const contentWithoutStyleBlocks = content.replace(/<style[^]+?<\/style>/gi, '') // Remove inline vue styles
40+
return contentWithoutStyleBlocks.match(/[\w-.:/]+(?<!:)/g) || []
3841
},
3942
extensions: ['html', 'vue', 'js']
4043
}
@@ -82,22 +85,22 @@ export default function nuxtPurgeCss(moduleOptions) {
8285

8386
if (mode === MODES.webpack) {
8487
if (!this.options.build.extractCSS) {
85-
logger.error(`Webpack mode only works with build.extractCSS set to *true*. Either extract your CSS or use 'postcss' mode`)
88+
logger.error('Webpack mode only works with build.extractCSS set to *true*. Either extract your CSS or use \'postcss\' mode')
8689
return
8790
}
8891
this.extendBuild(webpackFn(enabled, config))
8992
return
9093
}
9194

9295
if (Array.isArray(this.options.build.postcss)) {
93-
logger.error(`build.postcss array option detected. Purgecss will only work in postcss mode with an option object`)
96+
logger.error('build.postcss array option detected. Purgecss will only work in postcss mode with an option object')
9497
return
9598
}
9699

97100
if (config.extractors) {
98101
config.extractors.forEach((e) => {
99102
if (e.extractor && e.extractor.extract) {
100-
logger.warn(`extractors need to be defined as function now, transformed class definition to function`)
103+
logger.warn('extractors need to be defined as function now, transformed class definition to function')
101104
e.extractor = e.extractor.extract
102105
}
103106
})
@@ -128,4 +131,5 @@ const webpackFn = (enabled, purgeCssConfig) => (config, ctx) => {
128131
logger.success('Module initialized in webpack mode')
129132
}
130133

134+
module.exports = nuxtPurgeCss
131135
module.exports.meta = require('../package.json')

package.json

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "nuxt-purgecss",
3-
"version": "0.2.1",
4-
"description": "",
3+
"version": "1.0.0",
4+
"description": "Drop superfluous CSS! A neat PurgeCSS wrapper for Nuxt.js",
55
"license": "MIT",
66
"contributors": [
77
{
@@ -21,15 +21,10 @@
2121
},
2222
"scripts": {
2323
"dev": "nuxt --config-file test/fixture/configs/postcss/default.js",
24-
"lint": "eslint lib test",
25-
"test": "yarn run lint && jest --detectOpenHandles",
26-
"release": "standard-version && git push --follow-tags && npm publish",
27-
"commitlint": "commitlint -E HUSKY_GIT_PARAMS",
28-
"coverage": "codecov"
24+
"lint": "eslint --ext .js,.vue .",
25+
"release": "yarn test && standard-version && git push --follow-tags && npm publish",
26+
"test": "yarn lint && jest"
2927
},
30-
"eslintIgnore": [
31-
"lib/templates/*.*"
32-
],
3328
"files": [
3429
"lib"
3530
],
@@ -41,7 +36,7 @@
4136
"css"
4237
],
4338
"engines": {
44-
"node": ">=8.0.0",
39+
"node": ">=10.0.0",
4540
"npm": ">=5.0.0"
4641
},
4742
"jest": {
@@ -61,25 +56,16 @@
6156
"purgecss-webpack-plugin": "^2.0.5"
6257
},
6358
"devDependencies": {
64-
"@commitlint/cli": "^7.5.2",
65-
"@commitlint/config-conventional": "^7.5.0",
66-
"@nuxtjs/eslint-config": "^0.0.1",
67-
"babel-eslint": "^10.0.1",
68-
"codecov": "^3.3.0",
69-
"eslint": "^5.16.0",
70-
"eslint-config-standard": "^12.0.0",
71-
"eslint-plugin-import": "^2.16.0",
72-
"eslint-plugin-jest": "^22.4.1",
73-
"eslint-plugin-node": "^8.0.1",
74-
"eslint-plugin-promise": "^4.1.1",
75-
"eslint-plugin-standard": "^4.0.0",
76-
"eslint-plugin-vue": "^5.2.2",
77-
"get-port": "^4.2.0",
59+
"@commitlint/cli": "latest",
60+
"@commitlint/config-conventional": "latest",
61+
"@nuxtjs/eslint-config": "latest",
62+
"@nuxtjs/module-test-utils": "latest",
63+
"eslint": "latest",
7864
"husky": "^1.3.1",
7965
"jest": "^23.6.0",
8066
"jsdom": "^13.2.0",
81-
"nuxt-edge": "^2.3.0-25706271.cca799c",
82-
"standard-version": "^4.4.0"
67+
"nuxt-edge": "latest",
68+
"standard-version": "latest"
8369
},
8470
"husky": {
8571
"hooks": {

test/fixture/components/Test.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
<template>
2-
<div class="ymca">
2+
<div class="ymca" :class="{ bound: true }">
33
Test
44
</div>
55
</template>
66

7-
<style src="./Test.css"/>
7+
<style src="./Test.css" />
8+
9+
<style>
10+
.inline-unused {
11+
color: blue;
12+
}
13+
14+
.bound {
15+
color: red;
16+
}
17+
</style>

0 commit comments

Comments
 (0)