This is a webpack plugin that can minimize the HTML with HTMLMinifier for all source directory files and copy into destinations directory during the Webpack build.
Install the plugin with npm:
$ npm install minify-html-webpack-plugin --save-dev
Please do not report issues related to HTML parsing and output on this repository. Report those issues to the html-minifier issue tracker.
Add the plugin to your webpack and config as follows:
const MinifyHtmlWebpackPlugin = require('minify-html-webpack-plugin');
const webpackConfig = {
plugins: [
new MinifyHtmlWebpackPlugin({
src: './storage/framework/views',
rules: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true,
minifyJS: true,
}
});
]
};
Paste below snippets into mix.js file.
const MinifyHtmlWebpackPlugin = require('minify-html-webpack-plugin');
const mix = require('laravel-mix');
mix.webpackConfig({
plugins: [
new MinifyHtmlWebpackPlugin({
src: './storage/framework/views',
dest: './storage/framework/views',
ignoreFileNameRegex: /\.(gitignore|php)$/,
ignoreFileContentsRegex: /(<\?xml version)/,
rules: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true,
minifyJS: true,
}
})
]
});
You can pass configuration options to MinifyHtmlWebpackPlugin
. Each configuration has following items:
dir
: Optional. Base dir to find the files, if not provided, use the root of webpack context.src
: Required. source directory path.dest
: Optional. destination directory path. Paste minified HTML contents fromsrc
directory files intodest
directory, if not provided, paste intosrc
directory and will be overwritten.ignoreFileNameRegex
: Optional. Regex Expression to ingnore files in the src directory if it matches with the file name, if not provided, will minimize all files in src directory.`ignoreFileContentsRegex
: Optional. Regex Expression to ingnore files in the src directory if it matches with the file contents, if not provided, will minimize all files in src directory.`rules
: Required. See the html-minifer docs for all available options.
This project is licensed under MIT.