@@ -3,10 +3,7 @@ const glob = require('glob-all')
3
3
4
4
const logger = require ( './logger' )
5
5
6
- const MODES = {
7
- webpack : 'webpack' ,
8
- postcss : 'postcss'
9
- }
6
+ const { MODES , DEFAULTS } = require ( './constants' )
10
7
11
8
function nuxtPurgeCss ( moduleOptions ) {
12
9
const { srcDir, purgeCSS = { } } = Object . assign ( { } , this . options )
@@ -15,42 +12,12 @@ function nuxtPurgeCss (moduleOptions) {
15
12
16
13
logger . start ( 'Loading module' )
17
14
18
- const defaults = {
19
- mode : MODES . postcss ,
20
- enabled : this . options . debug ? false : ( { isDev, isClient } ) => ( ! isDev && isClient ) ,
21
- paths : [
22
- 'components/**/*.vue' ,
23
- 'layouts/**/*.vue' ,
24
- 'pages/**/*.vue' ,
25
- 'plugins/**/*.js' ,
26
- 'nuxt.config.js'
27
- ] ,
28
- styleExtensions : [ '.css' ] ,
29
- whitelist : [ 'body' , 'html' , 'nuxt-progress' , '__nuxt' , '__layout' ] ,
30
- whitelistPatterns : [
31
- / - ( l e a v e | e n t e r | a p p e a r ) ( | - ( t o | f r o m | a c t i v e ) ) $ / , // Normal transitions
32
- / ^ n u x t - l i n k ( | - e x a c t ) - a c t i v e $ / , // Nuxt link classes
33
- / ^ (? ! c u r s o r - m o v e ) .+ - m o v e $ / , // Move transitions
34
- / d a t a - v - .* / // Keep scoped styles
35
- ] ,
36
- whitelistPatternsChildren : [ ] ,
37
- extractors : [
38
- {
39
- extractor : ( content ) => {
40
- const contentWithoutStyleBlocks = content . replace ( / < s t y l e [ ^ ] + ?< \/ s t y l e > / gi, '' ) // Remove inline vue styles
41
- return contentWithoutStyleBlocks . match ( / [ \w - . : / ] + (?< ! : ) / g) || [ ]
42
- } ,
43
- extensions : [ 'html' , 'vue' , 'js' ]
44
- }
45
- ]
46
- }
47
-
48
15
/*
49
16
* Defaults
50
17
*/
51
18
52
19
const mergedConfig = Object . entries ( purgeCSS ) . reduce ( ( options , [ key , value ] ) => {
53
- const defaultValue = defaults [ key ]
20
+ const defaultValue = DEFAULTS [ key ]
54
21
55
22
if ( value && typeof value !== 'function' && Array . isArray ( defaultValue ) ) {
56
23
// Merge value with default value if array
@@ -65,7 +32,7 @@ function nuxtPurgeCss (moduleOptions) {
65
32
return options
66
33
} , { } )
67
34
68
- const { mode, enabled, ...config } = Object . assign ( { } , defaults , mergedConfig )
35
+ const { mode, enabled, ...config } = Object . assign ( { } , DEFAULTS , mergedConfig )
69
36
70
37
// transform relative paths
71
38
config . paths = glob . sync ( config . paths . map ( p => path . join ( srcDir , p ) ) )
0 commit comments