Skip to content

Commit

Permalink
chore: update module (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogobbosouza committed May 4, 2020
1 parent c123fef commit 032232c
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 246 deletions.
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Common
node_modules
dist
.nuxt
coverage
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ node_modules
*.iml
.idea
*.log*
.nuxt*
.nuxt
.vscode
.DS_STORE
.DS_Store
coverage
dist
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export default {

: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`.


## Options

### Defaults
Expand Down Expand Up @@ -105,7 +104,6 @@ export default {

### Override a default value


```js
//nuxt.config.js
export default {
Expand All @@ -121,7 +119,6 @@ export default {

### Append a value to the defaults


```js
//nuxt.config.js
export default {
Expand All @@ -137,7 +134,6 @@ export default {

### Override a default value


```js
//nuxt.config.js
export default {
Expand All @@ -152,6 +148,7 @@ export default {
```

### Use custom extractors

Only one extractor can be applied to each file extention.
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.

Expand Down Expand Up @@ -218,4 +215,3 @@ Copyright (c) Alexander Lichter

[license-src]: https://img.shields.io/npm/l/nuxt-purgecss.svg
[license-href]: https://npmjs.com/package/nuxt-purgecss

62 changes: 18 additions & 44 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,36 @@
"name": "nuxt-purgecss",
"version": "1.0.0",
"description": "Drop superfluous CSS! A neat PurgeCSS wrapper for Nuxt.js",
"keywords": [
"nuxtjs",
"nuxt",
"nuxt-module",
"purgecss",
"css"
],
"repository": "Developmint/nuxt-purgecss",
"license": "MIT",
"contributors": [
{
"name": "Alexander Lichter <npm@lichter.io>"
}
],
"main": "lib/module.js",
"repository": {
"mode": "git",
"url": "git+https://github.com/Developmint/nuxt-purgecss"
},
"bugs": {
"url": "https://github.com/Developmint/nuxt-purgecss/issues"
},
"publishConfig": {
"access": "public"
},
"files": [
"lib"
],
"scripts": {
"dev": "nuxt --config-file test/fixture/configs/postcss/default.js",
"lint": "eslint --ext .js,.vue .",
"release": "yarn test && standard-version && git push --follow-tags && npm publish",
"test": "yarn lint && jest"
},
"files": [
"lib"
],
"keywords": [
"nuxtjs",
"nuxt",
"nuxt-module",
"purgecss",
"css"
],
"engines": {
"node": ">=10.0.0",
"npm": ">=5.0.0"
},
"jest": {
"testEnvironment": "node",
"collectCoverage": true,
"coveragePathIgnorePatterns": [
"/node_modules/",
"/test/fixture"
],
"forceExit": true
},
"dependencies": {
"@fullhuman/postcss-purgecss": "^2.0.5",
"consola": "^1.4.5",
"glob-all": "^3.1.0",
"purgecss": "^2.0.5",
"purgecss-webpack-plugin": "^2.0.5"
"@fullhuman/postcss-purgecss": "^2.1.2",
"consola": "^2.11.3",
"glob-all": "^3.2.1",
"purgecss": "^2.1.2",
"purgecss-webpack-plugin": "^2.1.2"
},
"devDependencies": {
"@commitlint/cli": "latest",
Expand All @@ -63,14 +41,10 @@
"eslint": "latest",
"husky": "latest",
"jest": "latest",
"jsdom": "latest",
"nuxt-edge": "latest",
"standard-version": "latest"
},
"husky": {
"hooks": {
"pre-commit": "yarn run lint",
"commit-msg": "yarn run commitlint"
}
"publishConfig": {
"access": "public"
}
}
4 changes: 3 additions & 1 deletion test/fixture/configs/postcss/custom-options-fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ module.exports = {
resourceHints: false
},
dev: false,
modules: ['@@'],
buildModules: [
{ handler: require('../../../../') }
],
build: {
quiet: false,
optimization: {
Expand Down
4 changes: 3 additions & 1 deletion test/fixture/configs/postcss/custom-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ module.exports = {
resourceHints: false
},
dev: false,
modules: [['@@', { mode: 'postcss' }]],
buildModules: [
[require('../../../../'), { mode: 'postcss' }]
],
build: {
quiet: false,
optimization: {
Expand Down
4 changes: 3 additions & 1 deletion test/fixture/configs/postcss/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ module.exports = {
resourceHints: false
},
dev: false,
modules: ['@@'],
buildModules: [
{ handler: require('../../../../') }
],
build: {
quiet: false,
optimization: {
Expand Down
4 changes: 3 additions & 1 deletion test/fixture/configs/postcss/disabled.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ module.exports = {
resourceHints: false
},
dev: false,
modules: ['@@'],
buildModules: [
{ handler: require('../../../../') }
],
build: {
quiet: false,
optimization: {
Expand Down
4 changes: 3 additions & 1 deletion test/fixture/configs/webpack/custom-options-fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ module.exports = {
resourceHints: false
},
dev: false,
modules: ['@@'],
buildModules: [
{ handler: require('../../../../') }
],
build: {
quiet: false,
extractCSS: true,
Expand Down
4 changes: 3 additions & 1 deletion test/fixture/configs/webpack/custom-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ module.exports = {
resourceHints: false
},
dev: false,
modules: ['@@'],
buildModules: [
{ handler: require('../../../../') }
],
build: {
quiet: false,
extractCSS: true,
Expand Down
4 changes: 3 additions & 1 deletion test/fixture/configs/webpack/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ module.exports = {
resourceHints: false
},
dev: false,
modules: ['@@'],
buildModules: [
{ handler: require('../../../../') }
],
build: {
quiet: false,
extractCSS: true,
Expand Down
4 changes: 3 additions & 1 deletion test/fixture/configs/webpack/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ module.exports = {
render: {
resourceHints: false
},
modules: ['@@'],
buildModules: [
{ handler: require('../../../../') }
],
build: {
quiet: false,
extractCSS: true,
Expand Down
4 changes: 3 additions & 1 deletion test/fixture/configs/webpack/disabled.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ module.exports = {
resourceHints: false
},
dev: false,
modules: ['@@'],
buildModules: [
{ handler: require('../../../../') }
],
purgeCSS: {
mode: 'webpack',
enabled: false
Expand Down
36 changes: 12 additions & 24 deletions test/module.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,24 @@ const { promisify } = require('util')

const readFile = promisify(fsReadFile)

const consola = require('consola')
const { setup } = require('@nuxtjs/module-test-utils')
const logger = require('../lib/logger')

logger.mockTypes(() => jest.fn())
jest.setTimeout(60 * 1000)

describe('nuxt-purgecss', () => {
let log
let nuxt

beforeEach(() => {
log = jest.fn()
consola.clear().add({ log })
logger.clear()
})

describe('webpack', () => {
test('extract and purge css by default', async () => {
({ nuxt } = await setup(require('./fixture/configs/webpack/default')))

const consolaMessages = getConsolaMessages(log)
expect(consolaMessages).toContain('Module initialized in webpack mode')
expect(logger.success).toHaveBeenCalledWith('Module initialized in webpack mode')

const actualGlobalCSS = await getGlobalCSS()
const expectedGlobalCSS = {
Expand All @@ -45,15 +43,13 @@ describe('nuxt-purgecss', () => {
test('don\'t show webpack error message in dev', async () => {
({ nuxt } = await setup(require('./fixture/configs/webpack/dev')))

const consolaMessages = getConsolaMessages(log)
expect(consolaMessages).not.toContain('Webpack mode only works with build.extractCSS set to *true*. Either extract your CSS or use \'postcss\' mode')
expect(logger.error).not.toContain('Webpack mode only works with build.extractCSS set to *true*. Either extract your CSS or use \'postcss\' mode')
})

test('globally disable module', async () => {
({ nuxt } = await setup(require('./fixture/configs/webpack/disabled')))

const consolaMessages = getConsolaMessages(log)
expect(consolaMessages).toContain('Module is not enabled')
expect(logger.info).toHaveBeenCalledWith('Module is not enabled')

const globalCSS = await getGlobalCSS()
const expectedGlobalCSS = {
Expand All @@ -72,8 +68,7 @@ describe('nuxt-purgecss', () => {
test('define custom options for css lookup (concatenating)', async () => {
({ nuxt } = await setup(require('./fixture/configs/webpack/custom-options')))

const consolaMessages = getConsolaMessages(log)
expect(consolaMessages).toContain('Module initialized in webpack mode')
expect(logger.success).toHaveBeenCalledWith('Module initialized in webpack mode')

const globalCSS = await getGlobalCSS()
const expectedGlobalCSS = {
Expand All @@ -94,8 +89,7 @@ describe('nuxt-purgecss', () => {
test('define custom function options for css lookup (overriding)', async () => {
({ nuxt } = await setup(require('./fixture/configs/webpack/custom-options-fn')))

const consolaMessages = getConsolaMessages(log)
expect(consolaMessages).toContain('Module initialized in webpack mode')
expect(logger.success).toHaveBeenCalledWith('Module initialized in webpack mode')

const globalCSS = await getGlobalCSS()
const expectedGlobalCSS = {
Expand Down Expand Up @@ -139,8 +133,7 @@ describe('nuxt-purgecss', () => {
test('purge css by default', async () => {
({ nuxt } = await setup(require('./fixture/configs/postcss/default')))

const consolaMessages = getConsolaMessages(log)
expect(consolaMessages).toContain('Module initialized in postcss mode')
expect(logger.success).toHaveBeenCalledWith('Module initialized in postcss mode')

const actualGlobalCSS = await getGlobalCSS('js')
const expectedGlobalCSS = {
Expand All @@ -161,8 +154,7 @@ describe('nuxt-purgecss', () => {
test('globally disable module', async () => {
({ nuxt } = await setup(require('./fixture/configs/postcss/disabled')))

const consolaMessages = getConsolaMessages(log)
expect(consolaMessages).toContain('Module is not enabled')
expect(logger.info).toHaveBeenCalledWith('Module is not enabled')

const globalCSS = await getGlobalCSS('js')
const expectedGlobalCSS = {
Expand All @@ -181,8 +173,7 @@ describe('nuxt-purgecss', () => {
test('define custom options for css lookup (concatenating)', async () => {
({ nuxt } = await setup(require('./fixture/configs/postcss/custom-options')))

const consolaMessages = getConsolaMessages(log)
expect(consolaMessages).toContain('Module initialized in postcss mode')
expect(logger.success).toHaveBeenCalledWith('Module initialized in postcss mode')

const globalCSS = await getGlobalCSS('js')
const expectedGlobalCSS = {
Expand All @@ -203,8 +194,7 @@ describe('nuxt-purgecss', () => {
test('define custom function options for css lookup (overriding)', async () => {
({ nuxt } = await setup(require('./fixture/configs/postcss/custom-options-fn')))

const consolaMessages = getConsolaMessages(log)
expect(consolaMessages).toContain('Module initialized in postcss mode')
expect(logger.success).toHaveBeenCalledWith('Module initialized in postcss mode')

const globalCSS = await getGlobalCSS('js')
const expectedGlobalCSS = {
Expand Down Expand Up @@ -247,5 +237,3 @@ const checkCSS = (expected, actual) => {
}

const getFileContent = path => readFile(path, 'utf-8')

const getConsolaMessages = log => log.mock.calls.map(([res]) => res.message)

0 comments on commit 032232c

Please sign in to comment.