Skip to content

Commit cb38a65

Browse files
fix: superfluous error message in dev mode (#4)
1 parent 9b5cf96 commit cb38a65

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Before diving into the individual attributes, here are the default settings of t
4545
```js
4646
{
4747
mode: MODES.webpack,
48-
enabled: ({ isDev, isClient }) => (!isDev && isClient),
48+
enabled: ({ isDev, isClient }) => (!isDev && isClient), // or `false` when in dev/debug mode
4949
paths: [
5050
'components/**/*.vue',
5151
'layouts/**/*.vue',
@@ -93,11 +93,11 @@ Defines the mode, PurgeCSS should be used in.
9393
#### enabled
9494

9595
* Type: `Boolean` or `Function` (only for webpack mode, will receive the build.extend ctx)
96-
* Default: `({ isDev, isClient }) => (!isDev && isClient)` (Only activates in production mode)
96+
* Default: `({ isDev, isClient }) => (!isDev && isClient)` (only activates in production mode) or `false` in debug/dev mode
9797

9898
Enables/Disables the module
9999

100-
* If false, the module won't be activated at all
100+
* If it evaluates to false, the module won't be activated at all
101101
* If a function is given, it'll be properly evaluated in webpack mode (in postcss mode it'll be handled as true)
102102

103103

lib/module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default function nuxtPurgeCss() {
1515

1616
const defaults = {
1717
mode: MODES.webpack,
18-
enabled: ({ isDev, isClient }) => (!isDev && isClient),
18+
enabled: this.options.debug ? false : ({ isDev, isClient }) => (!isDev && isClient),
1919
paths: [
2020
'components/**/*.vue',
2121
'layouts/**/*.vue',

test/fixture/configs/webpack/dev.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const { resolve } = require('path')
2+
3+
module.exports = {
4+
rootDir: resolve(__dirname, '../../../../'),
5+
srcDir: resolve(__dirname, '../../'),
6+
css: ['~/assets/a.css'],
7+
render: {
8+
resourceHints: false
9+
},
10+
modules: ['@@'],
11+
build: {
12+
quiet: false,
13+
extractCSS: true,
14+
optimization: {
15+
splitChunks: {
16+
name: true
17+
}
18+
},
19+
filenames: {
20+
css: () => '[name].css'
21+
}
22+
}
23+
}

test/module.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ describe('nuxt-purgecss', () => {
4040
expect(testCSS).toMatch('.ymca')
4141
})
4242

43+
test('don\'t show webpack error message in dev', async () => {
44+
nuxt = await setupNuxt(require('./fixture/configs/webpack/dev'))
45+
46+
const consolaMessages = log.mock.calls.map(c => c[0].message)
47+
expect(consolaMessages).not.toContain('Webpack mode only works with build.extractCSS set to *true*. Either extract your CSS or use \'postcss\' mode')
48+
})
49+
4350
test('globally disable module', async () => {
4451
nuxt = await setupNuxt(require('./fixture/configs/webpack/disabled'))
4552

0 commit comments

Comments
 (0)