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

Commit

Permalink
v1.5.0
Browse files Browse the repository at this point in the history
update dependencies including purgecss 1.3.0
  • Loading branch information
Ffloriel committed Apr 21, 2019
1 parent 56be3d3 commit 5c69273
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 88 deletions.
94 changes: 47 additions & 47 deletions __tests__/cases/path-and-whitelist-functions/webpack.config.js
Original file line number Diff line number Diff line change
@@ -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"]
}
]
})
]
};
}
22 changes: 11 additions & 11 deletions lib/purgecss-webpack-plugin.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -205,49 +205,49 @@ 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 () {};
var assetsFromCompilation = assets(compilation.assets, ['.css']); // Go through chunks and purge as configured

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;
}

Expand Down
22 changes: 11 additions & 11 deletions lib/purgecss-webpack-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -209,49 +209,49 @@ 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 () {};
var assetsFromCompilation = assets(compilation.assets, ['.css']); // Go through chunks and purge as configured

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;
}

Expand Down
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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": {
Expand Down
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5c69273

Please sign in to comment.