Минимизация css, корректировка правил, хеширование файлов, настройки сборок (#6)

This commit is contained in:
Nikolay
2020-07-09 16:56:54 +03:00
committed by GitHub
parent 72cc821f99
commit 3fe0b232fd
7 changed files with 1471 additions and 44 deletions

View File

@ -1,18 +1,35 @@
// eslint-disable-next-line no-undef
const path = require('path');
// eslint-disable-next-line no-undef
const HtmlWebpackPlugin = require('html-webpack-plugin');
// eslint-disable-next-line no-undef
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
// eslint-disable-next-line no-undef
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
module.exports = {
// eslint-disable-next-line no-undef
module.exports = (env, argv) => ({
entry: './src/app.js',
output: {
filename: 'script.js',
filename: '[hash].js',
// eslint-disable-next-line no-undef
path: path.resolve(__dirname, 'dist'),
},
devServer: {
compress: true,
port: 9000,
},
optimization: {
splitChunks: {
chunks: 'all',
cacheGroups: {
defaultVendors: {
test: /[\\/]node_modules[\\/]/,
enforce: true,
},
}
},
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
@ -20,7 +37,7 @@ module.exports = {
template: './src/app.html'
}),
new MiniCssExtractPlugin({
filename: 'style.css',
filename: '[hash].css',
}),
],
module: {
@ -31,14 +48,24 @@ module.exports = {
},
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader'
],
},
{
test: /\.js$/,
exclude: /node_modules/,
use: [
'babel-loader',
'eslint-loader'
{
loader: 'eslint-loader',
options: (argv.mode === 'production') ? {
failOnError: true,
failOnWarning: true,
} : {},
}
]
},
{
@ -66,4 +93,4 @@ module.exports = {
},
],
},
};
});