@@ -5,55 +5,53 @@ import * as parse from './parse'
5
5
import * as search from './search'
6
6
7
7
export default class PurgecssPlugin {
8
- constructor ( options ) {
9
- this . options = options
10
- }
8
+ constructor ( options ) {
9
+ this . options = options
10
+ }
11
11
12
- apply ( compiler ) {
13
- compiler . plugin ( 'this-compilation' , compilation => {
14
- const entryPaths = parse . entryPaths ( this . options . paths )
12
+ apply ( compiler ) {
13
+ compiler . plugin ( 'this-compilation' , compilation => {
14
+ const entryPaths = parse . entryPaths ( this . options . paths )
15
15
16
- parse . flatten ( entryPaths ) . forEach ( p => {
17
- if ( ! fs . existsSync ( p ) )
18
- throw new Error ( `Path ${ p } does not exist.` )
19
- } )
20
-
21
- compilation . plugin ( 'additional-assets' , cb => {
22
- // Go through chunks and purge as configured
23
- compilation . chunks . forEach (
24
- ( { name : chunkName , files, modules } ) => {
25
- const assetsToPurge = search
26
- . assets ( compilation . assets , [ '.css' ] )
27
- . filter ( asset => files . indexOf ( asset . name ) >= 0 )
16
+ parse . flatten ( entryPaths ) . forEach ( p => {
17
+ if ( ! fs . existsSync ( p ) ) throw new Error ( `Path ${ p } does not exist.` )
18
+ } )
28
19
29
- assetsToPurge . forEach ( ( { name, asset } ) => {
30
- const filesToSearch = parse
31
- . entries ( entryPaths , chunkName )
32
- . concat (
33
- search . files (
34
- modules ,
35
- this . options . moduleExtensions || [ ] ,
36
- file => file . resource
37
- )
38
- )
39
- . filter ( v => ! v . endsWith ( '.css' ) )
20
+ compilation . plugin ( 'additional-assets' , cb => {
21
+ // Go through chunks and purge as configured
22
+ compilation . chunks . forEach ( chunk => {
23
+ const { name : chunkName , files } = chunk
24
+ const modules = chunk . mapModules ( mod => mod )
25
+ const assetsToPurge = search
26
+ . assets ( compilation . assets , [ '.css' ] )
27
+ . filter ( asset => files . indexOf ( asset . name ) >= 0 )
40
28
41
- // Compile through Purgecss and attach to output.
42
- // This loses sourcemaps should there be any!
43
- const purgecss = new Purgecss ( {
44
- content : filesToSearch ,
45
- css : [ asset . source ( ) ] ,
46
- stdin : true
47
- } )
48
- compilation . assets [ name ] = new ConcatSource (
49
- purgecss . purge ( ) [ 0 ] . css
50
- )
51
- } )
52
- }
29
+ assetsToPurge . forEach ( ( { name, asset } ) => {
30
+ const filesToSearch = parse
31
+ . entries ( entryPaths , chunkName )
32
+ . concat (
33
+ search . files (
34
+ modules ,
35
+ this . options . moduleExtensions || [ ] ,
36
+ file => file . resource
53
37
)
38
+ )
39
+ . filter ( v => ! v . endsWith ( '.css' ) )
54
40
55
- cb ( )
41
+ // Compile through Purgecss and attach to output.
42
+ // This loses sourcemaps should there be any!
43
+ const purgecss = new Purgecss ( {
44
+ ...this . options ,
45
+ content : filesToSearch ,
46
+ css : [ asset . source ( ) ] ,
47
+ stdin : true
56
48
} )
49
+ compilation . assets [ name ] = new ConcatSource ( purgecss . purge ( ) [ 0 ] . css )
50
+ } )
57
51
} )
58
- }
52
+
53
+ cb ( )
54
+ } )
55
+ } )
56
+ }
59
57
}
0 commit comments