Answer the question
In order to leave comments, you need to log in
How to optimize webpack build of html-webpack-plugin?
Got on one project. I'm doing the front. I noticed such a thing: the project is going for quite a long time. Full assembly - a few minutes, hot-reload - a minute. I decided to look what was the matter and this is what I found:
The project is made in such a way that each physical page is defined as a separate one:
new HtmlWebpackPlugin({
filename: 'my-page/index.html',
template: './sources/my-page/index.html',
chunks: ['my-page', 'common'],
hash: true
})
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
toastr: 'toastr',
moment: 'moment-timezone',
Highcharts: 'highcharts',
html2canvas: 'html2canvas',
Highcharts3D: 'highcharts/highcharts-3d',
HighchartsExporting: 'highcharts/modules/exporting',
HighchartsDrilldown: 'highcharts/modules/drilldown.js',
tinycolor: 'tinycolor2'
})
const HtmlWebpackPlugin = require('html-webpack-plugin');
const commonConfig = require('./webpack.common.js');
const moduleESLint = require('./module.eslint.js');
const webpackMerge = require('webpack-merge');
const moduleStyle = require('./module.style');
const webpack = require('webpack');
const glob = require('glob');
const ENV = 'prod';
/**
* Определяем настройки сжатия HTML-страниц
* @type {{}}
*/
const htmlMinifierOptions = {
collapseWhitespace: true,
html5: true,
ignoreCustomComments: true,
minifyCSS: true,
minifyJS: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeRedundantAttributes: true
};
const productionConfig = {
entry: glob.sync('./sources/**/*-component.js').reduce((entries, entry) => Object.assign(entries, {
[entry.split('/').pop().replace('.js', '').replace('-component', '')]: entry
}), {}),
output: {
filename: '[name]/[name].bundle.js',
path: [__dirname, '/../target/'].join()
},
plugins: [
new HtmlWebpackPlugin({
filename: 'p1/index.html',
template: './sources/p1/index.html',
chunks: ['p1', 'common'],
minify: htmlMinifierOptions,
contextPort: '',
dictionaryContextPort: '',
favoriteListContextPort: '',
registryListContextPort: '',
hash: true
}),
// ... more HtmlWebpackPlugin
new webpack.LoaderOptionsPlugin({
minimize: false,
debug: true
})
]
};
module.exports = webpackMerge(
commonConfig({env: ENV}),
productionConfig,
moduleESLint(),
moduleStyle()
);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question