File tree Expand file tree Collapse file tree 3 files changed +37
-23
lines changed
packages/purgecss-webpack-plugin Expand file tree Collapse file tree 3 files changed +37
-23
lines changed Original file line number Diff line number Diff line change 1+ const path = require ( "path" ) ;
2+ const glob = require ( "glob" ) ;
3+
4+ const customExtractor = ( content ) => {
5+ const res = content . match ( / [ A - z 0 - 9 - :/ ] + / g) || [ ] ;
6+ return res ;
7+ } ;
8+
9+ const PATHS = {
10+ src : path . join ( __dirname , "src" ) ,
11+ } ;
12+
13+ module . exports = {
14+ paths : glob . sync ( `${ PATHS . src } /*` ) ,
15+ safelist : [ "safelisted" ] ,
16+ extractors : [
17+ {
18+ extractor : customExtractor ,
19+ extensions : [ "html" , "js" ] ,
20+ } ,
21+ ] ,
22+ }
Original file line number Diff line number Diff line change 1- const path = require ( "path" ) ;
2- const glob = require ( "glob" ) ;
31const MiniCssExtractPlugin = require ( "mini-css-extract-plugin" ) ;
42const { PurgeCSSPlugin } = require ( "../../../src/" ) ;
53
6- const customExtractor = ( content ) => {
7- const res = content . match ( / [ A - z 0 - 9 - :/ ] + / g) || [ ] ;
8- return res ;
9- } ;
10-
11- const PATHS = {
12- src : path . join ( __dirname , "src" ) ,
13- } ;
14-
154module . exports = {
165 mode : "development" ,
176 devtool : "source-map" ,
@@ -41,15 +30,6 @@ module.exports = {
4130 new MiniCssExtractPlugin ( {
4231 filename : "[name].css" ,
4332 } ) ,
44- new PurgeCSSPlugin ( {
45- paths : glob . sync ( `${ PATHS . src } /*` ) ,
46- safelist : [ "safelisted" ] ,
47- extractors : [
48- {
49- extractor : customExtractor ,
50- extensions : [ "html" , "js" ] ,
51- } ,
52- ] ,
53- } ) ,
33+ new PurgeCSSPlugin ( { } ) ,
5434 ] ,
5535} ;
Original file line number Diff line number Diff line change @@ -2,9 +2,9 @@ import * as fs from "fs";
22import * as path from "path" ;
33import {
44 PurgeCSS ,
5- defaultOptions ,
65 ResultPurge ,
76 UserDefinedOptions as PurgeCSSUserDefinedOptions ,
7+ defaultOptions ,
88} from "purgecss" ;
99import { Compilation , Compiler , sources } from "webpack" ;
1010import { PurgedStats , UserDefinedOptions } from "./types" ;
@@ -128,7 +128,19 @@ export class PurgeCSSPlugin {
128128 }
129129
130130 initializePlugin ( compilation : Compilation ) : void {
131- compilation . hooks . additionalAssets . tapPromise ( pluginName , ( ) => {
131+ compilation . hooks . additionalAssets . tapPromise ( pluginName , async ( ) => {
132+ let configFileOptions : UserDefinedOptions | undefined ;
133+ try {
134+ const t = path . resolve ( process . cwd ( ) , "purgecss.config.js" ) ;
135+ configFileOptions = await import ( t ) ;
136+ } catch {
137+ // no config file present
138+ }
139+ this . options = {
140+ ...( configFileOptions ? configFileOptions : { } ) ,
141+ ...this . options ,
142+ } ;
143+
132144 const entryPaths =
133145 typeof this . options . paths === "function"
134146 ? this . options . paths ( )
You can’t perform that action at this time.
0 commit comments