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

113 lines
2.8 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');
2022-04-19 18:21:16 -06:00
const ESLintPlugin = require('eslint-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const ROOT_DIR = path.resolve(__dirname);
const resolvePath = (...args) => path.resolve(ROOT_DIR, ...args);
const BUILD_DIR = resolvePath('build');
const PUBLIC_URL = process.env.PUBLIC_URL || '/';
module.exports = {
entry: ['webpack-hot-middleware/client?path=/reload_wss&timeout=2000&reload=true&autoConnect=true', `${ROOT_DIR}/../src/frontend/index.tsx`],
2022-04-19 18:21:16 -06:00
output: {
path: BUILD_DIR,
2022-04-19 18:21:16 -06:00
filename: 'assets/app.js',
publicPath: PUBLIC_URL,
2022-04-19 18:21:16 -06:00
},
resolve: {
extensions: ['.js', '.jsx','.ts','.tsx', '.json'],
2022-04-19 18:21:16 -06:00
alias: {
'@components': path.resolve(__dirname, 'src/frontend/components/'),
'@styles': path.resolve(__dirname, 'src/frontend/styles/'),
2022-04-19 18:21:16 -06:00
}
},
devtool: 'inline-source-map',
2022-04-19 18:21:16 -06:00
mode: 'development',
context: __dirname,
2022-04-19 18:21:16 -06:00
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)$/,
2022-04-19 18:21:16 -06:00
use: {
loader: 'babel-loader',
options: { plugins: ['react-refresh/babel'] }
},
exclude: /node_modules/,
2022-04-19 18:21:16 -06:00
},
{
test: /\.(css|sass|scss)$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader',
],
},
{
test: /\.(png|jpg|jpeg|gif|svg|ico|mp4|avi|ttf|otf|eot|woff|woff2|pdf)$/,
loader: 'file-loader',
options: {
name: 'assets/media/[name].[ext]',
},
},
{
test: /\.(ttf|otf|eot|woff|woff2)$/,
loader: 'url-loader',
options: {
name: 'assets/fonts/[name].[ext]',
esModule: false,
},
},
2022-04-19 18:21:16 -06:00
]
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new ReactRefreshWebpackPlugin(),
new MiniCssExtractPlugin({
filename: 'assets/app.css',
}),
new ESLintPlugin(),
new webpack.DefinePlugin({
'process.env': JSON.stringify(dotenv.parsed),
'process.env.PUBLIC_URL': JSON.stringify(PUBLIC_URL),
2022-04-19 18:21:16 -06:00
}),
new CopyPlugin({
patterns: [
{
from: `${ROOT_DIR}/../public/manifest.json`, to: '',
},
{
from: `${ROOT_DIR}/../public/favicon.ico`, to: '',
},
{
from: `${ROOT_DIR}/../public/logo192.png`, to: '',
},
{
from: `${ROOT_DIR}/../public/logo512.png`, to: '',
},
]
}),
2022-04-19 18:21:16 -06:00
],
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);
},
},
},
},
},
};