From 5c692739c2a0f092cb42251647bee68c99761a28 Mon Sep 17 00:00:00 2001 From: Ffloriel Date: Sun, 21 Apr 2019 14:09:41 +0200 Subject: [PATCH] v1.5.0 update dependencies including purgecss 1.3.0 --- .../webpack.config.js | 94 +++++++++---------- lib/purgecss-webpack-plugin.es.js | 22 ++--- lib/purgecss-webpack-plugin.js | 22 ++--- package.json | 30 +++--- src/index.js | 8 +- 5 files changed, 88 insertions(+), 88 deletions(-) diff --git a/__tests__/cases/path-and-whitelist-functions/webpack.config.js b/__tests__/cases/path-and-whitelist-functions/webpack.config.js index 930e084..05b674f 100644 --- a/__tests__/cases/path-and-whitelist-functions/webpack.config.js +++ b/__tests__/cases/path-and-whitelist-functions/webpack.config.js @@ -1,56 +1,56 @@ -const path = require("path"); -const glob = require("glob"); -const MiniCssExtractPlugin = require("mini-css-extract-plugin"); -const PurgecssPlugin = require("../../../src/").default; +const path = require('path') +const glob = require('glob') +const MiniCssExtractPlugin = require('mini-css-extract-plugin') +const PurgecssPlugin = require('../../../src/').default class CustomExtractor { - static extract(content) { - return content.match(/[A-z0-9-:/]+/g); - } + static extract(content) { + return content.match(/[A-z0-9-:/]+/g) + } } const PATHS = { - src: path.join(__dirname, "src") -}; + src: path.join(__dirname, 'src') +} module.exports = { - mode: "development", - entry: "./src/index.js", - optimization: { - splitChunks: { - cacheGroups: { - styles: { - name: "styles", - test: /\.css$/, - chunks: "all", - enforce: true + mode: 'development', + entry: './src/index.js', + optimization: { + splitChunks: { + cacheGroups: { + styles: { + name: 'styles', + test: /\.css$/, + chunks: 'all', + enforce: true + } + } } - } - } - }, - module: { - rules: [ - { - test: /\.css$/, - use: [MiniCssExtractPlugin.loader, "css-loader"] - } + }, + module: { + rules: [ + { + test: /\.css$/, + use: [MiniCssExtractPlugin.loader, 'css-loader'] + } + ] + }, + plugins: [ + new MiniCssExtractPlugin({ + filename: '[name].css' + }), + new PurgecssPlugin({ + paths: () => glob.sync(`${PATHS.src}/*`), + whitelist: () => ['whitelisted'], + whitelistPatterns: () => [/^whitelistedPat/], + whitelistPatternsChildren: () => [/^whitelistedPatternChildren/], + extractors: [ + { + extractor: CustomExtractor, + extensions: ['html', 'js'] + } + ] + }) ] - }, - plugins: [ - new MiniCssExtractPlugin({ - filename: "[name].css" - }), - new PurgecssPlugin({ - paths: () => glob.sync(`${PATHS.src}/*`), - whitelist: () => ["whitelisted"], - whitelistPatterns: () => [/^whitelistedPat/], - whitelistPatternsChildren: () => [/^whitelistedPatternChildren/], - extractors: [ - { - extractor: CustomExtractor, - extensions: ["html", "js"] - } - ] - }) - ] -}; +} diff --git a/lib/purgecss-webpack-plugin.es.js b/lib/purgecss-webpack-plugin.es.js index f859e23..696327f 100644 --- a/lib/purgecss-webpack-plugin.es.js +++ b/lib/purgecss-webpack-plugin.es.js @@ -95,7 +95,7 @@ var entryPaths = function entryPaths(paths) { }; var flatten = function flatten(paths) { return Array.isArray(paths) ? paths : Object.keys(paths).reduce(function (acc, val) { - return _toConsumableArray(acc).concat(_toConsumableArray(paths[val])); + return [].concat(_toConsumableArray(acc), _toConsumableArray(paths[val])); }, []); }; var entries = function entries(paths, chunkName) { @@ -205,24 +205,24 @@ function () { value: function initializePlugin(compilation) { var _this2 = this; - var entryPaths$$1 = entryPaths(this.options.paths); - flatten(entryPaths$$1).forEach(function (p) { + var entryPaths$1 = entryPaths(this.options.paths); + flatten(entryPaths$1).forEach(function (p) { if (!fs.existsSync(p)) throw new Error("Path ".concat(p, " does not exist.")); }); if (webpackVersion === 4) { compilation.hooks.additionalAssets.tap(pluginName, function () { - _this2.runPluginHook(compilation, entryPaths$$1); + _this2.runPluginHook(compilation, entryPaths$1); }); } else { compilation.plugin('additional-assets', function (callback) { - _this2.runPluginHook(compilation, entryPaths$$1, callback); + _this2.runPluginHook(compilation, entryPaths$1, callback); }); } } }, { key: "runPluginHook", - value: function runPluginHook(compilation, entryPaths$$1) { + value: function runPluginHook(compilation, entryPaths) { var _this3 = this; var callback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {}; @@ -230,24 +230,24 @@ function () { compilation.chunks.forEach(function (chunk) { var chunkName = chunk.name, - files$$1 = chunk.files; + files$1 = chunk.files; var assetsToPurge = assetsFromCompilation.filter(function (asset) { if (_this3.options.only) { return [].concat(_this3.options.only).some(function (only) { return asset.name.indexOf(only) >= 0; }); } else { - return files$$1.indexOf(asset.name) >= 0; + return files$1.indexOf(asset.name) >= 0; } }); assetsToPurge.forEach(function (_ref) { var name = _ref.name, asset = _ref.asset; - var filesToSearch = entries(entryPaths$$1, chunkName).concat(files(chunk, _this3.options.moduleExtensions || [], function (file) { + var filesToSearch = entries(entryPaths, chunkName).concat(files(chunk, _this3.options.moduleExtensions || [], function (file) { return file.resource; }, webpackVersion)).filter(function (v) { - for (var _i = 0; _i < styleExtensions.length; _i++) { - var ext = styleExtensions[_i]; + for (var _i = 0, _styleExtensions = styleExtensions; _i < _styleExtensions.length; _i++) { + var ext = _styleExtensions[_i]; if (v.endsWith(ext)) return false; } diff --git a/lib/purgecss-webpack-plugin.js b/lib/purgecss-webpack-plugin.js index 81131c0..a7ff0cc 100644 --- a/lib/purgecss-webpack-plugin.js +++ b/lib/purgecss-webpack-plugin.js @@ -99,7 +99,7 @@ var entryPaths = function entryPaths(paths) { }; var flatten = function flatten(paths) { return Array.isArray(paths) ? paths : Object.keys(paths).reduce(function (acc, val) { - return _toConsumableArray(acc).concat(_toConsumableArray(paths[val])); + return [].concat(_toConsumableArray(acc), _toConsumableArray(paths[val])); }, []); }; var entries = function entries(paths, chunkName) { @@ -209,24 +209,24 @@ function () { value: function initializePlugin(compilation) { var _this2 = this; - var entryPaths$$1 = entryPaths(this.options.paths); - flatten(entryPaths$$1).forEach(function (p) { + var entryPaths$1 = entryPaths(this.options.paths); + flatten(entryPaths$1).forEach(function (p) { if (!fs.existsSync(p)) throw new Error("Path ".concat(p, " does not exist.")); }); if (webpackVersion === 4) { compilation.hooks.additionalAssets.tap(pluginName, function () { - _this2.runPluginHook(compilation, entryPaths$$1); + _this2.runPluginHook(compilation, entryPaths$1); }); } else { compilation.plugin('additional-assets', function (callback) { - _this2.runPluginHook(compilation, entryPaths$$1, callback); + _this2.runPluginHook(compilation, entryPaths$1, callback); }); } } }, { key: "runPluginHook", - value: function runPluginHook(compilation, entryPaths$$1) { + value: function runPluginHook(compilation, entryPaths) { var _this3 = this; var callback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {}; @@ -234,24 +234,24 @@ function () { compilation.chunks.forEach(function (chunk) { var chunkName = chunk.name, - files$$1 = chunk.files; + files$1 = chunk.files; var assetsToPurge = assetsFromCompilation.filter(function (asset) { if (_this3.options.only) { return [].concat(_this3.options.only).some(function (only) { return asset.name.indexOf(only) >= 0; }); } else { - return files$$1.indexOf(asset.name) >= 0; + return files$1.indexOf(asset.name) >= 0; } }); assetsToPurge.forEach(function (_ref) { var name = _ref.name, asset = _ref.asset; - var filesToSearch = entries(entryPaths$$1, chunkName).concat(files(chunk, _this3.options.moduleExtensions || [], function (file) { + var filesToSearch = entries(entryPaths, chunkName).concat(files(chunk, _this3.options.moduleExtensions || [], function (file) { return file.resource; }, webpackVersion)).filter(function (v) { - for (var _i = 0; _i < styleExtensions.length; _i++) { - var ext = styleExtensions[_i]; + for (var _i = 0, _styleExtensions = styleExtensions; _i < _styleExtensions.length; _i++) { + var ext = _styleExtensions[_i]; if (v.endsWith(ext)) return false; } diff --git a/package.json b/package.json index 6471fe6..8dd0e8f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "purgecss-webpack-plugin", - "version": "1.4.0", + "version": "1.5.0", "description": "Purgecss plugin for webpack - Remove unused css", "main": "./lib/purgecss-webpack-plugin.js", "module": "./lib/purgecss-webpack-plugin.es.js", @@ -39,29 +39,29 @@ }, "homepage": "https://github.com/FullHuman/purgecss-webpack-plugin#readme", "devDependencies": { - "@babel/core": "^7.1.6", - "@babel/plugin-proposal-object-rest-spread": "^7.0.0", - "@babel/plugin-syntax-object-rest-spread": "^7.0.0", - "@babel/preset-env": "^7.1.6", + "@babel/core": "^7.4.3", + "@babel/plugin-proposal-object-rest-spread": "^7.4.3", + "@babel/plugin-syntax-object-rest-spread": "^7.2.0", + "@babel/preset-env": "^7.4.3", "babel-core": "^7.0.0-bridge.0", "babel-eslint": "^10.0.1", - "babel-jest": "^23.6.0", - "codacy-coverage": "^3.2.0", + "babel-jest": "^24.7.1", + "codacy-coverage": "^3.4.0", "css-loader": "^1.0.1", - "eslint": "^5.9.0", - "jest": "^23.6.0", + "eslint": "^5.16.0", + "jest": "^24.7.1", "mini-css-extract-plugin": "^0.4.4", - "prettier": "^1.15.2", - "rollup": "^0.67.3", - "rollup-plugin-babel": "^4.0.3", - "rollup-plugin-commonjs": "^9.2.0", - "rollup-plugin-node-resolve": "^3.4.0", + "prettier": "^1.17.0", + "rollup": "^1.10.1", + "rollup-plugin-babel": "^4.3.2", + "rollup-plugin-commonjs": "^9.3.4", + "rollup-plugin-node-resolve": "^4.2.3", "rollup-watch": "^4.3.1", "webpack": "^4 || ^3", "webpack-cli": "^3" }, "dependencies": { - "purgecss": "^1.1.0", + "purgecss": "^1.3.0", "webpack-sources": "^1.3.0" }, "peerDependencies": { diff --git a/src/index.js b/src/index.js index a7750e9..44f951d 100644 --- a/src/index.js +++ b/src/index.js @@ -25,8 +25,8 @@ export default class PurgecssPlugin { this.initializePlugin(compilation) }) compiler.hooks.done.tapAsync(pluginName, (stats, cb) => { - this.addStats(stats); - cb(); + this.addStats(stats) + cb() }) } else { compiler.plugin('this-compilation', compilation => { @@ -116,10 +116,10 @@ export default class PurgecssPlugin { } const purgecss = new Purgecss(options) - const purged = purgecss.purge()[0]; + const purged = purgecss.purge()[0] if (purged.rejected) { - purgedStats[name] = purged.rejected; + purgedStats[name] = purged.rejected } compilation.assets[name] = new ConcatSource(purged.css)