purgecss-webpack-plugin
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -104,11 +104,20 @@ import path from 'path'; | ||
}; | ||
var webpackVersion = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 3; | ||
var mods = []; | ||
Array.from(chunk.modulesIterable || [], function (module) { | ||
var file = getter(module); | ||
if (file) { | ||
mods.push(extensions.indexOf(path.extname(file)) >= 0 && file); | ||
} | ||
}); | ||
if (webpackVersion === 4) { | ||
Array.from(chunk.modulesIterable || [], function (module) { | ||
var file = getter(module); | ||
if (file) { | ||
mods.push(extensions.indexOf(path.extname(file)) >= 0 && file); | ||
} | ||
}); | ||
} else if (chunk.mapModules) { | ||
chunk.mapModules(function (module) { | ||
var file = getter(module); | ||
if (!file) return null; | ||
return extensions.indexOf(path.extname(file)) >= 0 && file; | ||
}); | ||
} | ||
@@ -120,2 +129,4 @@ return mods.filter(function (a) { | ||
var webpackVersion = 4; | ||
var styleExtensions = ['.css', '.scss', '.styl', '.sass', '.less']; | ||
@@ -136,84 +147,116 @@ var pluginName = 'PurgeCSS'; | ||
compiler.hooks.compilation.tap(pluginName, function (compilation) { | ||
var entryPaths$$1 = entryPaths(_this.options.paths); | ||
if (typeof compiler.hooks === 'undefined') { | ||
webpackVersion = 3; | ||
} | ||
flatten(entryPaths$$1).forEach(function (p) { | ||
if (!fs.existsSync(p)) throw new Error('Path ' + p + ' does not exist.'); | ||
if (webpackVersion === 4) { | ||
compiler.hooks.compilation.tap(pluginName, function (compilation) { | ||
_this.initializePlugin(compilation); | ||
}); | ||
} else { | ||
compiler.plugin('this-compilation', function (compilation) { | ||
_this.initializePlugin(compilation); | ||
}); | ||
} | ||
} | ||
}, { | ||
key: 'initializePlugin', | ||
value: function initializePlugin(compilation) { | ||
var _this2 = this; | ||
var entryPaths$$1 = entryPaths(this.options.paths); | ||
flatten(entryPaths$$1).forEach(function (p) { | ||
if (!fs.existsSync(p)) throw new Error('Path ' + p + ' does not exist.'); | ||
}); | ||
if (webpackVersion === 4) { | ||
compilation.hooks.additionalAssets.tap(pluginName, function () { | ||
var assetsFromCompilation = assets(compilation.assets, ['.css']); | ||
// Go through chunks and purge as configured | ||
_this2.runPluginHook(compilation, entryPaths$$1); | ||
}); | ||
} else { | ||
compilation.plugin('additional-assets', function (callback) { | ||
_this2.runPluginHook(compilation, entryPaths$$1, callback); | ||
}); | ||
} | ||
} | ||
}, { | ||
key: 'runPluginHook', | ||
value: function runPluginHook(compilation, entryPaths$$1) { | ||
var _this3 = this; | ||
compilation.chunks.forEach(function (chunk) { | ||
var chunkName = chunk.name, | ||
files$$1 = chunk.files; | ||
var callback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {}; | ||
var assetsToPurge = assetsFromCompilation.filter(function (asset) { | ||
if (_this.options.only) { | ||
return [].concat(_this.options.only).some(function (only) { | ||
return asset.name.indexOf(only) >= 0; | ||
}); | ||
} else { | ||
return files$$1.indexOf(asset.name) >= 0; | ||
} | ||
}); | ||
var assetsFromCompilation = assets(compilation.assets, ['.css']); | ||
// Go through chunks and purge as configured | ||
assetsToPurge.forEach(function (_ref) { | ||
var name = _ref.name, | ||
asset = _ref.asset; | ||
compilation.chunks.forEach(function (chunk) { | ||
var chunkName = chunk.name, | ||
files$$1 = chunk.files; | ||
var filesToSearch = entries(entryPaths$$1, chunkName).concat(files(chunk, _this.options.moduleExtensions || [], function (file) { | ||
return file.resource; | ||
})).filter(function (v) { | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
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; | ||
} | ||
}); | ||
try { | ||
for (var _iterator = styleExtensions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var ext = _step.value; | ||
assetsToPurge.forEach(function (_ref) { | ||
var name = _ref.name, | ||
asset = _ref.asset; | ||
if (v.endsWith(ext)) return false; | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
var filesToSearch = entries(entryPaths$$1, chunkName).concat(files(chunk, _this3.options.moduleExtensions || [], function (file) { | ||
return file.resource; | ||
}, webpackVersion)).filter(function (v) { | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
return true; | ||
}); | ||
try { | ||
for (var _iterator = styleExtensions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var ext = _step.value; | ||
// Compile through Purgecss and attach to output. | ||
// This loses sourcemaps should there be any! | ||
var options = _extends({}, _this.options, { | ||
content: filesToSearch, | ||
css: [{ | ||
raw: asset.source() | ||
}] | ||
}); | ||
if (typeof options.whitelist === 'function') { | ||
options.whitelist = options.whitelist(); | ||
if (v.endsWith(ext)) return false; | ||
} | ||
if (typeof options.whitelistPatterns === 'function') { | ||
options.whitelistPatterns = options.whitelistPatterns(); | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
var purgecss = new Purgecss(options); | ||
compilation.assets[name] = new ConcatSource(purgecss.purge()[0].css); | ||
}); | ||
} | ||
return true; | ||
}); | ||
// cb() | ||
// Compile through Purgecss and attach to output. | ||
// This loses sourcemaps should there be any! | ||
var options = _extends({}, _this3.options, { | ||
content: filesToSearch, | ||
css: [{ | ||
raw: asset.source() | ||
}] | ||
}); | ||
if (typeof options.whitelist === 'function') { | ||
options.whitelist = options.whitelist(); | ||
} | ||
if (typeof options.whitelistPatterns === 'function') { | ||
options.whitelistPatterns = options.whitelistPatterns(); | ||
} | ||
var purgecss = new Purgecss(options); | ||
compilation.assets[name] = new ConcatSource(purgecss.purge()[0].css); | ||
}); | ||
}); | ||
callback(); | ||
} | ||
@@ -220,0 +263,0 @@ }]); |
@@ -108,11 +108,20 @@ 'use strict'; | ||
}; | ||
var webpackVersion = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 3; | ||
var mods = []; | ||
Array.from(chunk.modulesIterable || [], function (module) { | ||
var file = getter(module); | ||
if (file) { | ||
mods.push(extensions.indexOf(path.extname(file)) >= 0 && file); | ||
} | ||
}); | ||
if (webpackVersion === 4) { | ||
Array.from(chunk.modulesIterable || [], function (module) { | ||
var file = getter(module); | ||
if (file) { | ||
mods.push(extensions.indexOf(path.extname(file)) >= 0 && file); | ||
} | ||
}); | ||
} else if (chunk.mapModules) { | ||
chunk.mapModules(function (module) { | ||
var file = getter(module); | ||
if (!file) return null; | ||
return extensions.indexOf(path.extname(file)) >= 0 && file; | ||
}); | ||
} | ||
@@ -124,2 +133,4 @@ return mods.filter(function (a) { | ||
var webpackVersion = 4; | ||
var styleExtensions = ['.css', '.scss', '.styl', '.sass', '.less']; | ||
@@ -140,84 +151,116 @@ var pluginName = 'PurgeCSS'; | ||
compiler.hooks.compilation.tap(pluginName, function (compilation) { | ||
var entryPaths$$1 = entryPaths(_this.options.paths); | ||
if (typeof compiler.hooks === 'undefined') { | ||
webpackVersion = 3; | ||
} | ||
flatten(entryPaths$$1).forEach(function (p) { | ||
if (!fs.existsSync(p)) throw new Error('Path ' + p + ' does not exist.'); | ||
if (webpackVersion === 4) { | ||
compiler.hooks.compilation.tap(pluginName, function (compilation) { | ||
_this.initializePlugin(compilation); | ||
}); | ||
} else { | ||
compiler.plugin('this-compilation', function (compilation) { | ||
_this.initializePlugin(compilation); | ||
}); | ||
} | ||
} | ||
}, { | ||
key: 'initializePlugin', | ||
value: function initializePlugin(compilation) { | ||
var _this2 = this; | ||
var entryPaths$$1 = entryPaths(this.options.paths); | ||
flatten(entryPaths$$1).forEach(function (p) { | ||
if (!fs.existsSync(p)) throw new Error('Path ' + p + ' does not exist.'); | ||
}); | ||
if (webpackVersion === 4) { | ||
compilation.hooks.additionalAssets.tap(pluginName, function () { | ||
var assetsFromCompilation = assets(compilation.assets, ['.css']); | ||
// Go through chunks and purge as configured | ||
_this2.runPluginHook(compilation, entryPaths$$1); | ||
}); | ||
} else { | ||
compilation.plugin('additional-assets', function (callback) { | ||
_this2.runPluginHook(compilation, entryPaths$$1, callback); | ||
}); | ||
} | ||
} | ||
}, { | ||
key: 'runPluginHook', | ||
value: function runPluginHook(compilation, entryPaths$$1) { | ||
var _this3 = this; | ||
compilation.chunks.forEach(function (chunk) { | ||
var chunkName = chunk.name, | ||
files$$1 = chunk.files; | ||
var callback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {}; | ||
var assetsToPurge = assetsFromCompilation.filter(function (asset) { | ||
if (_this.options.only) { | ||
return [].concat(_this.options.only).some(function (only) { | ||
return asset.name.indexOf(only) >= 0; | ||
}); | ||
} else { | ||
return files$$1.indexOf(asset.name) >= 0; | ||
} | ||
}); | ||
var assetsFromCompilation = assets(compilation.assets, ['.css']); | ||
// Go through chunks and purge as configured | ||
assetsToPurge.forEach(function (_ref) { | ||
var name = _ref.name, | ||
asset = _ref.asset; | ||
compilation.chunks.forEach(function (chunk) { | ||
var chunkName = chunk.name, | ||
files$$1 = chunk.files; | ||
var filesToSearch = entries(entryPaths$$1, chunkName).concat(files(chunk, _this.options.moduleExtensions || [], function (file) { | ||
return file.resource; | ||
})).filter(function (v) { | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
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; | ||
} | ||
}); | ||
try { | ||
for (var _iterator = styleExtensions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var ext = _step.value; | ||
assetsToPurge.forEach(function (_ref) { | ||
var name = _ref.name, | ||
asset = _ref.asset; | ||
if (v.endsWith(ext)) return false; | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
var filesToSearch = entries(entryPaths$$1, chunkName).concat(files(chunk, _this3.options.moduleExtensions || [], function (file) { | ||
return file.resource; | ||
}, webpackVersion)).filter(function (v) { | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
return true; | ||
}); | ||
try { | ||
for (var _iterator = styleExtensions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var ext = _step.value; | ||
// Compile through Purgecss and attach to output. | ||
// This loses sourcemaps should there be any! | ||
var options = _extends({}, _this.options, { | ||
content: filesToSearch, | ||
css: [{ | ||
raw: asset.source() | ||
}] | ||
}); | ||
if (typeof options.whitelist === 'function') { | ||
options.whitelist = options.whitelist(); | ||
if (v.endsWith(ext)) return false; | ||
} | ||
if (typeof options.whitelistPatterns === 'function') { | ||
options.whitelistPatterns = options.whitelistPatterns(); | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
var purgecss = new Purgecss(options); | ||
compilation.assets[name] = new webpackSources.ConcatSource(purgecss.purge()[0].css); | ||
}); | ||
} | ||
return true; | ||
}); | ||
// cb() | ||
// Compile through Purgecss and attach to output. | ||
// This loses sourcemaps should there be any! | ||
var options = _extends({}, _this3.options, { | ||
content: filesToSearch, | ||
css: [{ | ||
raw: asset.source() | ||
}] | ||
}); | ||
if (typeof options.whitelist === 'function') { | ||
options.whitelist = options.whitelist(); | ||
} | ||
if (typeof options.whitelistPatterns === 'function') { | ||
options.whitelistPatterns = options.whitelistPatterns(); | ||
} | ||
var purgecss = new Purgecss(options); | ||
compilation.assets[name] = new webpackSources.ConcatSource(purgecss.purge()[0].css); | ||
}); | ||
}); | ||
callback(); | ||
} | ||
@@ -224,0 +267,0 @@ }]); |
{ | ||
"name": "purgecss-webpack-plugin", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Purgecss plugin for webpack - Remove unused css", | ||
@@ -50,6 +50,6 @@ "main": "./lib/purgecss-webpack-plugin.js", | ||
"eslint": "^4.19.1", | ||
"jest": "^22.4.4", | ||
"jest": "^23.1.0", | ||
"mini-css-extract-plugin": "^0.4.0", | ||
"prettier": "^1.12.1", | ||
"rollup": "^0.59.2", | ||
"prettier": "^1.13.4", | ||
"rollup": "^0.60.0", | ||
"rollup-plugin-babel": "^3.0.4", | ||
@@ -59,9 +59,13 @@ "rollup-plugin-commonjs": "^9.1.3", | ||
"rollup-watch": "^4.3.1", | ||
"webpack-cli": "^2.1.3" | ||
"webpack-cli": "^3.0.2", | ||
"webpack": "^4.11.1" | ||
}, | ||
"dependencies": { | ||
"purgecss": "^1.0.0", | ||
"webpack": "^4.8.3", | ||
"purgecss": "^1.0.1", | ||
"webpack-sources": "^1.1.0" | ||
}, | ||
"peerDependencies": { | ||
"webpack": "^4.11.1", | ||
"webpack-cli": "^3.0.2" | ||
} | ||
} |
@@ -16,8 +16,4 @@ # purgecss-webpack-plugin | ||
## Install | ||
```sh | ||
npm i purgecss-webpack-plugin -D | ||
# or webpack 3 | ||
npm i purgecss-webpack-plugin@0.23.0 -D | ||
``` | ||
@@ -32,3 +28,3 @@ | ||
const glob = require('glob') | ||
const MiniCssExtractPlugin = require("mini-css-extract-plugin") | ||
const MiniCssExtractPlugin = require('mini-css-extract-plugin') | ||
const PurgecssPlugin = require('purgecss-webpack-plugin') | ||
@@ -74,3 +70,3 @@ | ||
new PurgecssPlugin({ | ||
paths: glob.sync(`${PATHS.src}/*`, { nodir: true }) | ||
paths: glob.sync(`${PATHS.src}/**/*`, { nodir: true }) | ||
}) | ||
@@ -77,0 +73,0 @@ ] |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27863
466
4
18
194
+ Addedchalk@2.4.2(transitive)
+ Addedcross-spawn@6.0.6(transitive)
+ Addeddetect-file@1.0.0(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedexpand-tilde@2.0.2(transitive)
+ Addedfindup-sync@3.0.0(transitive)
+ Addedglobal-modules@1.0.02.0.0(transitive)
+ Addedglobal-prefix@1.0.23.0.0(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedhomedir-polyfill@1.0.3(transitive)
+ Addedimport-local@2.0.0(transitive)
+ Addedini@1.3.8(transitive)
+ Addedinterpret@1.4.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addednice-try@1.0.5(transitive)
+ Addedparse-passwd@1.0.0(transitive)
+ Addedpath-key@2.0.1(transitive)
+ Addedresolve-cwd@2.0.0(transitive)
+ Addedresolve-dir@1.0.1(transitive)
+ Addedresolve-from@3.0.0(transitive)
+ Addedshebang-command@1.2.0(transitive)
+ Addedshebang-regex@1.0.0(transitive)
+ Addedsupports-color@5.5.06.1.0(transitive)
+ Addedv8-compile-cache@2.4.0(transitive)
+ Addedwebpack-cli@3.3.12(transitive)
+ Addedwhich@1.3.1(transitive)
+ Addedyargs@13.3.2(transitive)
+ Addedyargs-parser@13.1.2(transitive)
- Removedwebpack@^4.8.3
Updatedpurgecss@^1.0.1