Skip to content

Commit f7cc1d4

Browse files
committed
v0.10.0
- update dev dependencies - build v0.10.0
1 parent 67cb520 commit f7cc1d4

File tree

4 files changed

+393
-107
lines changed

4 files changed

+393
-107
lines changed

lib/purgecss-webpack-plugin.es.js

Lines changed: 175 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,96 @@ import Purgecss from 'purgecss';
33
import { ConcatSource } from 'webpack-sources';
44
import path from 'path';
55

6-
const entryPaths = paths => {
7-
const ret = paths || [];
6+
var classCallCheck = function (instance, Constructor) {
7+
if (!(instance instanceof Constructor)) {
8+
throw new TypeError("Cannot call a class as a function");
9+
}
10+
};
11+
12+
var createClass = function () {
13+
function defineProperties(target, props) {
14+
for (var i = 0; i < props.length; i++) {
15+
var descriptor = props[i];
16+
descriptor.enumerable = descriptor.enumerable || false;
17+
descriptor.configurable = true;
18+
if ("value" in descriptor) descriptor.writable = true;
19+
Object.defineProperty(target, descriptor.key, descriptor);
20+
}
21+
}
22+
23+
return function (Constructor, protoProps, staticProps) {
24+
if (protoProps) defineProperties(Constructor.prototype, protoProps);
25+
if (staticProps) defineProperties(Constructor, staticProps);
26+
return Constructor;
27+
};
28+
}();
29+
30+
31+
32+
33+
34+
35+
36+
var _extends = Object.assign || function (target) {
37+
for (var i = 1; i < arguments.length; i++) {
38+
var source = arguments[i];
39+
40+
for (var key in source) {
41+
if (Object.prototype.hasOwnProperty.call(source, key)) {
42+
target[key] = source[key];
43+
}
44+
}
45+
}
46+
47+
return target;
48+
};
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
82+
83+
84+
var toConsumableArray = function (arr) {
85+
if (Array.isArray(arr)) {
86+
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
87+
88+
return arr2;
89+
} else {
90+
return Array.from(arr);
91+
}
92+
};
93+
94+
var entryPaths = function entryPaths(paths) {
95+
var ret = paths || [];
896

997
// Convert possible string to an array
1098
if (typeof ret === 'string') {
@@ -14,9 +102,13 @@ const entryPaths = paths => {
14102
return ret;
15103
};
16104

17-
const flatten = paths => Array.isArray(paths) ? paths : Object.keys(paths).reduce((acc, val) => [...acc, ...paths[val]], []);
105+
var flatten = function flatten(paths) {
106+
return Array.isArray(paths) ? paths : Object.keys(paths).reduce(function (acc, val) {
107+
return [].concat(toConsumableArray(acc), toConsumableArray(paths[val]));
108+
}, []);
109+
};
18110

19-
const entries = (paths, chunkName) => {
111+
var entries = function entries(paths, chunkName) {
20112
if (Array.isArray(paths)) {
21113
return paths;
22114
}
@@ -25,61 +117,99 @@ const entries = (paths, chunkName) => {
25117
return [];
26118
}
27119

28-
const ret = paths[chunkName];
120+
var ret = paths[chunkName];
29121

30122
return Array.isArray(ret) ? ret : [ret];
31123
};
32124

33-
const assets = (assets = [], extensions = []) => Object.keys(assets).map(name => {
34-
return extensions.indexOf(path.extname(name.indexOf('?') >= 0 ? name.split('?').slice(0, -1).join('') : name)) >= 0 && { name, asset: assets[name] };
35-
}).filter(a => a);
125+
var assets = function assets() {
126+
var assets = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
127+
var extensions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
128+
return Object.keys(assets).map(function (name) {
129+
return extensions.indexOf(path.extname(name.indexOf('?') >= 0 ? name.split('?').slice(0, -1).join('') : name)) >= 0 && { name: name, asset: assets[name] };
130+
}).filter(function (a) {
131+
return a;
132+
});
133+
};
36134

37-
const files = (modules = {}, extensions = [], getter = a => a) => Object.keys(modules).map(name => {
38-
const file = getter(modules[name]);
135+
var files = function files() {
136+
var modules = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
137+
var extensions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
138+
var getter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (a) {
139+
return a;
140+
};
141+
return Object.keys(modules).map(function (name) {
142+
var file = getter(modules[name]);
143+
144+
if (!file) {
145+
return null;
146+
}
147+
148+
return extensions.indexOf(path.extname(file)) >= 0 && file;
149+
}).filter(function (a) {
150+
return a;
151+
});
152+
};
39153

40-
if (!file) {
41-
return null;
42-
}
154+
var PurgecssPlugin = function () {
155+
function PurgecssPlugin(options) {
156+
classCallCheck(this, PurgecssPlugin);
43157

44-
return extensions.indexOf(path.extname(file)) >= 0 && file;
45-
}).filter(a => a);
158+
this.options = options;
159+
}
46160

47-
class PurgecssPlugin {
48-
constructor(options) {
49-
this.options = options;
50-
}
161+
createClass(PurgecssPlugin, [{
162+
key: 'apply',
163+
value: function apply(compiler) {
164+
var _this = this;
51165

52-
apply(compiler) {
53-
compiler.plugin('this-compilation', compilation => {
54-
const entryPaths$$1 = entryPaths(this.options.paths);
166+
compiler.plugin('this-compilation', function (compilation) {
167+
var entryPaths$$1 = entryPaths(_this.options.paths);
168+
169+
flatten(entryPaths$$1).forEach(function (p) {
170+
if (!fs.existsSync(p)) throw new Error('Path ' + p + ' does not exist.');
171+
});
55172

56-
flatten(entryPaths$$1).forEach(p => {
57-
if (!fs.existsSync(p)) throw new Error(`Path ${p} does not exist.`);
173+
compilation.plugin('additional-assets', function (cb) {
174+
// Go through chunks and purge as configured
175+
compilation.chunks.forEach(function (chunk) {
176+
var chunkName = chunk.name,
177+
files$$1 = chunk.files;
178+
179+
var modules = chunk.mapModules(function (mod) {
180+
return mod;
181+
});
182+
var assetsToPurge = assets(compilation.assets, ['.css']).filter(function (asset) {
183+
return files$$1.indexOf(asset.name) >= 0;
58184
});
59185

60-
compilation.plugin('additional-assets', cb => {
61-
// Go through chunks and purge as configured
62-
compilation.chunks.forEach(({ name: chunkName, files: files$$1, modules }) => {
63-
const assetsToPurge = assets(compilation.assets, ['.css']).filter(asset => files$$1.indexOf(asset.name) >= 0);
64-
65-
assetsToPurge.forEach(({ name, asset }) => {
66-
const filesToSearch = entries(entryPaths$$1, chunkName).concat(files(modules, this.options.moduleExtensions || [], file => file.resource)).filter(v => !v.endsWith('.css'));
67-
68-
// Compile through Purgecss and attach to output.
69-
// This loses sourcemaps should there be any!
70-
const purgecss = new Purgecss({
71-
content: filesToSearch,
72-
css: [asset.source()],
73-
stdin: true
74-
});
75-
compilation.assets[name] = new ConcatSource(purgecss.purge()[0].css);
76-
});
77-
});
78-
79-
cb();
186+
assetsToPurge.forEach(function (_ref) {
187+
var name = _ref.name,
188+
asset = _ref.asset;
189+
190+
var filesToSearch = entries(entryPaths$$1, chunkName).concat(files(modules, _this.options.moduleExtensions || [], function (file) {
191+
return file.resource;
192+
})).filter(function (v) {
193+
return !v.endsWith('.css');
194+
});
195+
196+
// Compile through Purgecss and attach to output.
197+
// This loses sourcemaps should there be any!
198+
var purgecss = new Purgecss(_extends({}, _this.options, {
199+
content: filesToSearch,
200+
css: [asset.source()],
201+
stdin: true
202+
}));
203+
compilation.assets[name] = new ConcatSource(purgecss.purge()[0].css);
80204
});
205+
});
206+
207+
cb();
81208
});
209+
});
82210
}
83-
}
211+
}]);
212+
return PurgecssPlugin;
213+
}();
84214

85215
export default PurgecssPlugin;

0 commit comments

Comments
 (0)