Skip to content

Commit

Permalink
Add folders option
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiandedeyne committed May 24, 2018
1 parent dafd211 commit 82c0237
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "laravel-mix-purgecss",
"version": "2.1.3",
"version": "2.2.0-rc.1",
"description": "Purgecss wrapper for Laravel Mix",
"main": "src/index.js",
"repository": {
Expand Down
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const mix = require('laravel-mix');
const { flatMap } = require('./util');
const createPurgeCssPlugin = require('./createPurgeCssPlugin');

// This is kind of an undocumented Mix function, hope it stays around! Easy to
Expand All @@ -20,6 +21,7 @@ class PurgeCss {
this.options = Object.assign(
{
enabled: mix.inProduction(),
folders: ['resources'],
extensions: ['html', 'js', 'jsx', 'ts', 'tsx', 'php', 'vue'],
globs: [],
whitelistPatterns: [],
Expand All @@ -29,7 +31,11 @@ class PurgeCss {

this.options.globs.push(
rootPath('app/**/*.php'),
...this.options.extensions.map(extension => rootPath(`resources/**/*.${extension}`))
...flatMap(this.options.folders, folder => {
return this.options.extensions.map(extension =>
rootPath(`${folder}/**/*.${extension}`)
);
})
);

this.options.whitelistPatterns.push(/-active$/, /-enter$/, /-leave-to$/);
Expand Down
4 changes: 4 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ module.exports = {

return omitted;
},

flatMap(array, callback) {
return Array.prototype.concat.apply([], array.map(callback));
},
};

0 comments on commit 82c0237

Please sign in to comment.