Skip to content
This repository was archived by the owner on Feb 1, 2020. It is now read-only.

Commit d896adf

Browse files
committed
support css preprocessors
add support for: - .scss - .sass - .styl - .less remove files with above extensions from purgecss content
1 parent 5701b48 commit d896adf

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

lib/purgecss-webpack-plugin.es.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ var files = function files(chunk) {
146146
});
147147
};
148148

149+
var styleExtensions = ['.css', '.scss', '.styl', '.sass', '.less'];
150+
149151
var PurgecssPlugin = function () {
150152
function PurgecssPlugin(options) {
151153
classCallCheck(this, PurgecssPlugin);
@@ -189,7 +191,32 @@ var PurgecssPlugin = function () {
189191
var filesToSearch = entries(entryPaths$$1, chunkName).concat(files(chunk, _this.options.moduleExtensions || [], function (file) {
190192
return file.resource;
191193
})).filter(function (v) {
192-
return !v.endsWith('.css');
194+
var _iteratorNormalCompletion = true;
195+
var _didIteratorError = false;
196+
var _iteratorError = undefined;
197+
198+
try {
199+
for (var _iterator = styleExtensions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
200+
var ext = _step.value;
201+
202+
if (v.endsWith(ext)) return false;
203+
}
204+
} catch (err) {
205+
_didIteratorError = true;
206+
_iteratorError = err;
207+
} finally {
208+
try {
209+
if (!_iteratorNormalCompletion && _iterator.return) {
210+
_iterator.return();
211+
}
212+
} finally {
213+
if (_didIteratorError) {
214+
throw _iteratorError;
215+
}
216+
}
217+
}
218+
219+
return true;
193220
});
194221

195222
// Compile through Purgecss and attach to output.

lib/purgecss-webpack-plugin.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ var files = function files(chunk) {
150150
});
151151
};
152152

153+
var styleExtensions = ['.css', '.scss', '.styl', '.sass', '.less'];
154+
153155
var PurgecssPlugin = function () {
154156
function PurgecssPlugin(options) {
155157
classCallCheck(this, PurgecssPlugin);
@@ -193,7 +195,32 @@ var PurgecssPlugin = function () {
193195
var filesToSearch = entries(entryPaths$$1, chunkName).concat(files(chunk, _this.options.moduleExtensions || [], function (file) {
194196
return file.resource;
195197
})).filter(function (v) {
196-
return !v.endsWith('.css');
198+
var _iteratorNormalCompletion = true;
199+
var _didIteratorError = false;
200+
var _iteratorError = undefined;
201+
202+
try {
203+
for (var _iterator = styleExtensions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
204+
var ext = _step.value;
205+
206+
if (v.endsWith(ext)) return false;
207+
}
208+
} catch (err) {
209+
_didIteratorError = true;
210+
_iteratorError = err;
211+
} finally {
212+
try {
213+
if (!_iteratorNormalCompletion && _iterator.return) {
214+
_iterator.return();
215+
}
216+
} finally {
217+
if (_didIteratorError) {
218+
throw _iteratorError;
219+
}
220+
}
221+
}
222+
223+
return true;
197224
});
198225

199226
// Compile through Purgecss and attach to output.

src/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { ConcatSource } from 'webpack-sources'
44
import * as parse from './parse'
55
import * as search from './search'
66

7+
const styleExtensions = ['.css', '.scss', '.styl', '.sass', '.less']
8+
79
export default class PurgecssPlugin {
810
constructor(options) {
911
this.options = options
@@ -44,7 +46,12 @@ export default class PurgecssPlugin {
4446
file => file.resource
4547
)
4648
)
47-
.filter(v => !v.endsWith('.css'))
49+
.filter(v => {
50+
for (let ext of styleExtensions) {
51+
if (v.endsWith(ext)) return false
52+
}
53+
return true
54+
})
4855

4956
// Compile through Purgecss and attach to output.
5057
// This loses sourcemaps should there be any!

0 commit comments

Comments
 (0)