create-react-ssr/src/webpack.config.dev.js

71 lines
2.2 KiB
JavaScript
Raw Normal View History

const path = require('path');
const dotenv = require('dotenv').config();
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
module.exports = {
entry: ['webpack-hot-middleware/client?path=/reload_wss&timeout=2000&overlay=false&reload=true', './frontend/index.js'],
output: {
path: path.resolve(__dirname, 'build'),
filename: 'assets/app.js',
},
resolve: {
extensions: ['.js', '.jsx'],
alias: {
'@components': path.resolve(__dirname, 'frontend/components/'),
'@styles': path.resolve(__dirname, 'frontend/styles/'),
}
},
mode: 'development',
module: {
rules: [
{
test: /\.(js|jsx|tsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: { plugins: ['react-refresh/babel'] }
},
},
{
test: /\.(css|sass|scss)$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader',
],
},
]
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new ReactRefreshWebpackPlugin(),
new MiniCssExtractPlugin({
filename: 'assets/app.css',
}),
new webpack.DefinePlugin({
'process.env': JSON.stringify(dotenv.parsed),
}),
],
optimization: {
splitChunks: {
chunks: 'async',
cacheGroups: {
vendors: {
name: 'vendors',
chunks: 'all',
reuseExistingChunk: true,
priority: 1,
filename: 'assets/vendor.js',
enforce: true,
test (module, chunks){
const name = module.nameForCondition && module.nameForCondition();
return chunks.name !== 'vendors' && /[\\/]node_modules[\\/]/.test(name);
},
},
},
},
},
}