function handleButtons() {
const buttons = document.querySelectorAll('.btn');
if (!buttons.length) return; // строка лишняя, так как forEach на пустом NodeList не выбрасывает исключений
buttons.forEach(...);
}
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const PurgecssPlugin = require('purgecss-webpack-plugin');
const isDev = process.env.NODE_ENV === 'development';
const isProd = !isDev;
const plugins = [
new MiniCssExtractPlugin({
filename: 'assets/css/style.css'
}),
new HtmlWebpackPlugin({
template: "./src/index.html"
})
];
if (isProd) {
plugins.push(
new PurgecssPlugin({
paths: glob.sync(`${path.join(__dirname, 'dist')}/**/*`, { nodir: true }),
})
);
}
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'assets/js/bundle.js'
},
module: {
rules: [{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader'
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
// options...
}
}
]
}]
},
plugins: plugins
};
"scripts": {
"dev": "cross-env NODE_ENV=development webpack serve --config webpack/webpack.config.babel.js --mode development",
"prod": "cross-env NODE_ENV=production webpack serve --config webpack/webpack.config.babel.js --mode production"
}
const isDev = process.env.NODE_ENV === 'development';
const isProd = !isDev;
if (isProd) {
// Используем PurgeCSS.
}