2022-04-11 09:25:51 -06:00
|
|
|
const path = require('path');
|
2022-04-17 21:59:56 -06:00
|
|
|
const dotenv = require('dotenv').config();
|
2022-04-19 09:26:24 -06:00
|
|
|
const webpack = require('webpack');
|
2022-04-19 17:09:35 -06:00
|
|
|
const CompressionWebpackPlugin = require('compression-webpack-plugin');
|
2022-04-13 10:48:10 -06:00
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
|
|
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
|
|
|
|
const TerserPlugin = require('terser-webpack-plugin');
|
2022-04-19 17:09:35 -06:00
|
|
|
const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
|
2022-04-13 10:48:10 -06:00
|
|
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
2022-04-19 18:21:16 -06:00
|
|
|
const ESLintPlugin = require('eslint-webpack-plugin');
|
2022-04-24 23:44:06 -06:00
|
|
|
const CopyPlugin = require('copy-webpack-plugin');
|
|
|
|
const { InjectManifest } = require('workbox-webpack-plugin');
|
2022-04-25 17:28:32 -06:00
|
|
|
const nodeExternals = require('webpack-node-externals');
|
2022-04-24 23:44:06 -06:00
|
|
|
const PUBLIC_URL = process.env.PUBLIC_URL || '/';
|
2022-04-11 09:25:51 -06:00
|
|
|
|
2022-04-25 17:28:32 -06:00
|
|
|
const frontendConfig = {
|
|
|
|
entry: {
|
|
|
|
frontend: './src/frontend/index.tsx',
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
path: path.resolve(__dirname, 'build'),
|
|
|
|
filename: 'assets/app-[name]-[fullhash].js',
|
|
|
|
publicPath: PUBLIC_URL,
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
extensions: ['.js', '.jsx','.ts','.tsx', '.json'],
|
|
|
|
alias: {
|
|
|
|
'@components': path.resolve(__dirname, 'src/frontend/components/'),
|
|
|
|
'@styles': path.resolve(__dirname, 'src/frontend/styles/'),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mode: 'production',
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.(js|jsx|ts|tsx)$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(css|sass|scss)$/,
|
|
|
|
use: [
|
|
|
|
MiniCssExtractPlugin.loader,
|
|
|
|
'css-loader',
|
|
|
|
'sass-loader',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new CompressionWebpackPlugin({
|
|
|
|
test: /\.(js|css)$/,
|
|
|
|
filename: '[path][base].gz',
|
|
|
|
}),
|
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
filename: 'assets/app-[fullhash].css',
|
|
|
|
}),
|
|
|
|
new WebpackManifestPlugin({
|
|
|
|
fileName: 'assets/manifest-hash.json',
|
|
|
|
}),
|
|
|
|
new CleanWebpackPlugin({
|
|
|
|
cleanOnceBeforeBuildPatterns: [
|
|
|
|
'**/*',
|
|
|
|
'!server/**',
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new ESLintPlugin(),
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env': JSON.stringify(dotenv.parsed),
|
|
|
|
'process.env.PUBLIC_URL': JSON.stringify(PUBLIC_URL),
|
|
|
|
}),
|
|
|
|
new CopyPlugin({
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
from: './public/manifest.json', to: '',
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
new InjectManifest({
|
|
|
|
swSrc: './service-worker.js',
|
|
|
|
swDest: 'service-worker.js',
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
optimization: {
|
|
|
|
minimize: true,
|
|
|
|
minimizer: [
|
|
|
|
new CssMinimizerPlugin(),
|
|
|
|
new TerserPlugin(),
|
|
|
|
],
|
|
|
|
splitChunks: {
|
|
|
|
chunks: 'async',
|
|
|
|
cacheGroups: {
|
|
|
|
vendors: {
|
|
|
|
name: 'vendors',
|
|
|
|
chunks: 'all',
|
|
|
|
reuseExistingChunk: true,
|
|
|
|
priority: 1,
|
|
|
|
filename: 'assets/vendor-[name]-[fullhash].js',
|
|
|
|
enforce: true,
|
|
|
|
test (module, chunks){
|
|
|
|
const name = module.nameForCondition && module.nameForCondition();
|
|
|
|
return chunks.name !== 'vendors' && /[\\/]node_modules[\\/]/.test(name);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const serverConfig = {
|
|
|
|
entry: {
|
|
|
|
server: './src/server/index.js',
|
|
|
|
},
|
|
|
|
target: "node",
|
|
|
|
externals: [nodeExternals()],
|
2022-04-19 18:21:16 -06:00
|
|
|
output: {
|
|
|
|
path: path.resolve(__dirname, 'build'),
|
2022-04-25 17:28:32 -06:00
|
|
|
filename: 'server/app-[name].js',
|
2022-04-24 23:44:06 -06:00
|
|
|
publicPath: PUBLIC_URL,
|
2022-04-19 18:21:16 -06:00
|
|
|
},
|
|
|
|
resolve: {
|
2022-04-22 09:00:14 -06:00
|
|
|
extensions: ['.js', '.jsx','.ts','.tsx', '.json'],
|
2022-04-19 18:21:16 -06:00
|
|
|
alias: {
|
2022-04-25 09:12:43 -06:00
|
|
|
'@components': path.resolve(__dirname, 'src/frontend/components/'),
|
|
|
|
'@styles': path.resolve(__dirname, 'src/frontend/styles/'),
|
2022-04-19 18:21:16 -06:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mode: 'production',
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
2022-04-22 09:00:14 -06:00
|
|
|
test: /\.(js|jsx|ts|tsx)$/,
|
2022-04-19 18:21:16 -06:00
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(css|sass|scss)$/,
|
|
|
|
use: [
|
|
|
|
MiniCssExtractPlugin.loader,
|
|
|
|
'css-loader',
|
|
|
|
'sass-loader',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new CompressionWebpackPlugin({
|
|
|
|
test: /\.(js|css)$/,
|
|
|
|
filename: '[path][base].gz',
|
|
|
|
}),
|
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
filename: 'assets/app-[fullhash].css',
|
|
|
|
}),
|
|
|
|
new WebpackManifestPlugin({
|
|
|
|
fileName: 'assets/manifest-hash.json',
|
|
|
|
}),
|
|
|
|
new CleanWebpackPlugin(),
|
|
|
|
new ESLintPlugin(),
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env': JSON.stringify(dotenv.parsed),
|
2022-04-24 23:44:06 -06:00
|
|
|
'process.env.PUBLIC_URL': JSON.stringify(PUBLIC_URL),
|
|
|
|
}),
|
|
|
|
new CopyPlugin({
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
from: './public/manifest.json', to: '',
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
new InjectManifest({
|
|
|
|
swSrc: './service-worker.js',
|
|
|
|
swDest: 'service-worker.js',
|
2022-04-19 18:21:16 -06:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
optimization: {
|
|
|
|
minimize: true,
|
|
|
|
minimizer: [
|
|
|
|
new CssMinimizerPlugin(),
|
|
|
|
new TerserPlugin(),
|
|
|
|
],
|
|
|
|
splitChunks: {
|
|
|
|
chunks: 'async',
|
|
|
|
cacheGroups: {
|
|
|
|
vendors: {
|
|
|
|
name: 'vendors',
|
|
|
|
chunks: 'all',
|
|
|
|
reuseExistingChunk: true,
|
|
|
|
priority: 1,
|
2022-04-25 17:28:32 -06:00
|
|
|
filename: 'assets/vendor-[name]-[fullhash].js',
|
2022-04-19 18:21:16 -06:00
|
|
|
enforce: true,
|
|
|
|
test (module, chunks){
|
|
|
|
const name = module.nameForCondition && module.nameForCondition();
|
|
|
|
return chunks.name !== 'vendors' && /[\\/]node_modules[\\/]/.test(name);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2022-04-25 17:28:32 -06:00
|
|
|
|
|
|
|
module.exports = [frontendConfig, serverConfig];
|