html-beautify-webpack-plugin
Advanced tools
Comparing version 1.0.4 to 1.0.5
39
index.js
@@ -0,1 +1,2 @@ | ||
const webpack = require('webpack') | ||
const _ = require('lodash') | ||
@@ -5,2 +6,3 @@ const chalk = require('chalk') | ||
const beautify = require('js-beautify').html | ||
const webpackLatest = !_.isNil(webpack.version) && /.*4(\.\d+){0,2}/gi.test(webpack.version) | ||
@@ -25,16 +27,29 @@ function HtmlBeautifyPlugin ({ config = {}, replace } = { config: {}, replace: [] }) { | ||
function htmlPluginDataFunction (htmlPluginData, callback, _this) { | ||
htmlPluginData.html = beautify(_.reduce(_this.options.replace, (res, item) => { | ||
if(typeof item === 'string' || item instanceof RegExp) | ||
return res.replace(item instanceof RegExp ? item : new RegExp(item, 'gi'), '') | ||
else | ||
return res.replace(item.test instanceof RegExp ? item.test : new RegExp(item.test, 'gi'), item.with || '') | ||
}, htmlPluginData.html), _this.options.config) | ||
callback(null, htmlPluginData) | ||
} | ||
HtmlBeautifyPlugin.prototype.apply = function (compiler) { | ||
compiler.plugin('compilation', compilation => | ||
compilation.plugin('html-webpack-plugin-after-html-processing', (htmlPluginData, callback) => { | ||
htmlPluginData.html = beautify(_.reduce(this.options.replace, (res, item) => { | ||
if(typeof item === 'string' || item instanceof RegExp) | ||
return res.replace(item instanceof RegExp ? item : new RegExp(item, 'gi'), '') | ||
else | ||
return res.replace(item.test instanceof RegExp ? item.test : new RegExp(item.test, 'gi'), item.with || '') | ||
}, htmlPluginData.html), this.options.config) | ||
callback(null, htmlPluginData) | ||
})) | ||
if (!webpackLatest) { | ||
compiler.plugin('compilation', compilation => | ||
compilation.plugin('html-webpack-plugin-after-html-processing', (htmlPluginData, callback) => { | ||
htmlPluginDataFunction(htmlPluginData, callback, this) | ||
}) | ||
) | ||
} else { | ||
compiler.hooks.compilation.tap('HtmlBeautifyPlugin', compilation => | ||
compilation.hooks.htmlWebpackPluginAfterHtmlProcessing.tapAsync('HtmlBeautifyPlugin', (htmlPluginData, callback) => { | ||
htmlPluginDataFunction(htmlPluginData, callback, this) | ||
}) | ||
) | ||
} | ||
} | ||
module.exports = HtmlBeautifyPlugin | ||
module.exports = HtmlBeautifyPlugin |
{ | ||
"name": "html-beautify-webpack-plugin", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Adapter for beautifyjs as webpack plugin, chained with HtmlWebpackPlugin", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
45
5462
4