Skip to content

Commit e91e5aa

Browse files
author
Marc Eickhoff
committed
Re-added the option to pass a file list
1 parent 49de317 commit e91e5aa

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ mix
3131
level: 2,
3232
format: mix.inProduction() ? false : 'beautify' // Beautify only in dev mode
3333
})
34+
35+
// Run clean-css only on one specific stylesheet
36+
.cleanCss({
37+
// ...
38+
}, 'src/app.scss')
39+
40+
// Run clean-css only on multiple specific stylesheets
41+
.cleanCss({
42+
// ...
43+
}, [
44+
'src/app.scss',
45+
'src/app.sass',
46+
])
3447
```
3548

3649
For more information about clean-css configurations please refer to their [documentation](https://github.com/jakubpawlowicz/clean-css/blob/master/README.md).

index.js

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const mix = require('laravel-mix');
2+
const path = require('path');
23

34
class CleanCss {
45

@@ -15,10 +16,26 @@ class CleanCss {
1516
* Register the component.
1617
*
1718
* @param {Object} options CleanCSS configuration object
19+
* @param {String|Array} files (optional) Files to apply clean-css to
1820
* @return {void}
1921
*/
20-
register(options) {
22+
register(options, files = null) {
23+
24+
// Convert single given file to array
25+
if (typeof files === 'string') files = [files];
26+
27+
// Make every file path absolute
28+
if (Array.isArray(files)) {
29+
Object.keys(files).forEach(function (key) {
30+
if (!path.isAbsolute(files[key])) {
31+
files[key] = path.resolve(files[key]);
32+
}
33+
});
34+
}
35+
36+
// Create properties
2137
this.options = options;
38+
this.files = files;
2239
}
2340

2441
/**
@@ -29,15 +46,16 @@ class CleanCss {
2946
*/
3047
webpackConfig(webpackConfig) {
3148
let options = this.options;
49+
let files = this.files;
3250

3351
// Where to insert the clean-css-loader
3452
const insertBefore = "postcss-loader";
3553

3654
// Go through all rules
3755
webpackConfig.module.rules.forEach(function (rule) {
3856

39-
// Skip rules without loaders
40-
if (typeof rule.use === "undefined") return;
57+
// Skip rules without loaders or files that are not in the file list
58+
if (typeof rule.use === "undefined" || (files && !files.includes(rule.test))) return;
4159

4260
// Go through all loaders of a rule
4361
rule.use.forEach(function (loader) {

0 commit comments

Comments
 (0)