From 5013961353b7e28d446d892b697c896dfb2a0520 Mon Sep 17 00:00:00 2001 From: Alexander Lichter Date: Wed, 24 Oct 2018 11:05:30 +0100 Subject: [PATCH] fix: superfluous error message in dev mode --- README.md | 6 +++--- lib/module.js | 2 +- test/fixture/configs/webpack/dev.js | 23 +++++++++++++++++++++++ test/module.test.js | 7 +++++++ 4 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 test/fixture/configs/webpack/dev.js diff --git a/README.md b/README.md index 4ec41d3..6d65efe 100755 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Before diving into the individual attributes, here are the default settings of t ```js { mode: MODES.webpack, - enabled: ({ isDev, isClient }) => (!isDev && isClient), + enabled: ({ isDev, isClient }) => (!isDev && isClient), // or `false` when in dev/debug mode paths: [ 'components/**/*.vue', 'layouts/**/*.vue', @@ -93,11 +93,11 @@ Defines the mode, PurgeCSS should be used in. #### enabled * Type: `Boolean` or `Function` (only for webpack mode, will receive the build.extend ctx) -* Default: `({ isDev, isClient }) => (!isDev && isClient)` (Only activates in production mode) +* Default: `({ isDev, isClient }) => (!isDev && isClient)` (only activates in production mode) or `false` in debug/dev mode Enables/Disables the module -* If false, the module won't be activated at all +* If it evaluates to false, the module won't be activated at all * If a function is given, it'll be properly evaluated in webpack mode (in postcss mode it'll be handled as true) diff --git a/lib/module.js b/lib/module.js index e599752..8948e27 100644 --- a/lib/module.js +++ b/lib/module.js @@ -15,7 +15,7 @@ export default function nuxtPurgeCss() { const defaults = { mode: MODES.webpack, - enabled: ({ isDev, isClient }) => (!isDev && isClient), + enabled: this.options.debug ? false : ({ isDev, isClient }) => (!isDev && isClient), paths: [ 'components/**/*.vue', 'layouts/**/*.vue', diff --git a/test/fixture/configs/webpack/dev.js b/test/fixture/configs/webpack/dev.js new file mode 100644 index 0000000..600039c --- /dev/null +++ b/test/fixture/configs/webpack/dev.js @@ -0,0 +1,23 @@ +const { resolve } = require('path') + +module.exports = { + rootDir: resolve(__dirname, '../../../../'), + srcDir: resolve(__dirname, '../../'), + css: ['~/assets/a.css'], + render: { + resourceHints: false + }, + modules: ['@@'], + build: { + quiet: false, + extractCSS: true, + optimization: { + splitChunks: { + name: true + } + }, + filenames: { + css: () => '[name].css' + } + } +} diff --git a/test/module.test.js b/test/module.test.js index f35f472..856d534 100644 --- a/test/module.test.js +++ b/test/module.test.js @@ -40,6 +40,13 @@ describe('nuxt-purgecss', () => { expect(testCSS).toMatch('.ymca') }) + test('don\'t show webpack error message in dev', async () => { + nuxt = await setupNuxt(require('./fixture/configs/webpack/dev')) + + const consolaMessages = log.mock.calls.map(c => c[0].message) + expect(consolaMessages).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 setupNuxt(require('./fixture/configs/webpack/disabled'))