From 82c02374f7cb9b573f5e7835d24bab873c586cce Mon Sep 17 00:00:00 2001 From: Sebastian De Deyne Date: Thu, 24 May 2018 19:31:02 +0200 Subject: [PATCH] Add folders option --- package.json | 2 +- src/index.js | 8 +++++++- src/util.js | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index bde884b..0d6cbba 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/index.js b/src/index.js index c70d02a..9bce6a7 100644 --- a/src/index.js +++ b/src/index.js @@ -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 @@ -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: [], @@ -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$/); diff --git a/src/util.js b/src/util.js index 73eb4cf..c1a6103 100644 --- a/src/util.js +++ b/src/util.js @@ -10,4 +10,8 @@ module.exports = { return omitted; }, + + flatMap(array, callback) { + return Array.prototype.concat.apply([], array.map(callback)); + }, };