const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const autoprefixer = require('autoprefixer');
const Webpack = require('webpack');
const dotenv = require('dotenv');
const path = require('path');
const htmlWebpackPluginConfig = new HtmlWebpackPlugin({
template: __dirname + '/src/public/index.html',
inject: 'body',
scriptLoading: 'defer',
});
const miniCssExtractConfig = new MiniCssExtractPlugin({
filename: '[name].[hash].css',
chunkFilename: '[id].[hash].css',
});
const DefinePluginConfig = new Webpack.DefinePlugin({
'process.env': JSON.stringify(dotenv.config().parsed),
});
const ESLintPluginConfig = new ESLintPlugin();
module.exports = {
mode: 'development',
entry: __dirname + '/src/index.js',
output: {
// path: __dirname + '/dist',
path: __dirname,
filename: '[name].[hash].js',
publicPath: '/',
},
optimization: {
// minimize: false,
splitChunks: {
chunks: 'async',
minSize: 20000,
minRemainingSize: 0,
minChunks: 1,
maxAsyncRequests: 30,
maxInitialRequests: 30,
enforceSizeThreshold: 50000,
cacheGroups: {
defaultVendors: {
test: /[\\/]node_modules[\\/]/,
priority: -10,
reuseExistingChunk: true,
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true,
},
},
},
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
use: ['babel-loader'],
exclude: [/node_modules/],
},
{
test: /\.(css)$/,
use: [MiniCssExtractPlugin.loader, { loader: 'css-loader' }],
},
{
test: /\.(scss)$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: {
exportGlobals: true,
localIdentName: '[local]--[hash:base64:5]',
auto: /\.module\.\w+$/i,
},
},
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
[
autoprefixer({
browsers: ['> 0%'],
}),
],
],
},
// TODO: только dev
sourceMap: true,
},
},
{
loader: 'sass-loader',
},
],
},
{
test: /\.(png|jp(e*)g|svg|gif)$/i,
use: [
{
loader: 'file-loader',
options: {
// name: 'images/[hash]-[name].[ext]',
name: '[path][name].[ext]',
},
},
],
},
],
},
resolve: {
alias: {
components: path.join(__dirname, 'src/components'),
constants: path.join(__dirname, 'src/constants'),
store: path.join(__dirname, 'src/store'),
pages: path.join(__dirname, 'src/pages'),
utils: path.join(__dirname, 'src/utils'),
api: path.join(__dirname, 'src/api'),
routes: path.join(__dirname, 'src/routes'),
schemes: path.join(__dirname, 'src/schemes'),
hooks: path.join(__dirname, 'src/hooks'),
},
extensions: ['.js', '.jsx'],
},
plugins: [htmlWebpackPluginConfig, miniCssExtractConfig, ESLintPluginConfig, DefinePluginConfig],
devServer: {
static: './src/public',
port: 3000,
historyApiFallback: {
index: '/',
disableDotRule: true,
},
hot: true,
},
};