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-11 09:25:51 -06:00
|
|
|
|
|
|
|
module.exports = {
|
2022-04-13 14:12:15 -06:00
|
|
|
entry: './frontend/index.js',
|
2022-04-11 09:25:51 -06:00
|
|
|
output: {
|
2022-04-13 10:48:10 -06:00
|
|
|
path: path.resolve(__dirname, 'build'),
|
2022-04-19 17:09:35 -06:00
|
|
|
filename: 'assets/app-[fullhash].js',
|
2022-04-13 10:48:10 -06:00
|
|
|
publicPath: '/',
|
2022-04-11 09:25:51 -06:00
|
|
|
},
|
|
|
|
resolve: {
|
2022-04-13 10:48:10 -06:00
|
|
|
extensions: ['.js', '.jsx'],
|
|
|
|
alias: {
|
2022-04-19 09:26:24 -06:00
|
|
|
'@components': path.resolve(__dirname, 'frontend/components/'),
|
2022-04-13 14:12:15 -06:00
|
|
|
'@styles': path.resolve(__dirname, 'frontend/styles/'),
|
2022-04-13 10:48:10 -06:00
|
|
|
}
|
2022-04-11 09:25:51 -06:00
|
|
|
},
|
2022-04-13 10:48:10 -06:00
|
|
|
mode: 'production',
|
2022-04-11 09:25:51 -06:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
2022-04-19 09:26:24 -06:00
|
|
|
test: /\.(js|jsx|tsx)$/,
|
2022-04-11 09:25:51 -06:00
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader',
|
2022-04-13 10:48:10 -06:00
|
|
|
},
|
2022-04-11 09:25:51 -06:00
|
|
|
},
|
|
|
|
{
|
2022-04-17 16:54:45 -06:00
|
|
|
test: /\.(css|sass|scss)$/,
|
2022-04-11 09:25:51 -06:00
|
|
|
use: [
|
2022-04-17 16:54:45 -06:00
|
|
|
MiniCssExtractPlugin.loader,
|
2022-04-13 10:48:10 -06:00
|
|
|
'css-loader',
|
|
|
|
'sass-loader',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2022-04-11 09:25:51 -06:00
|
|
|
},
|
|
|
|
plugins: [
|
2022-04-19 17:09:35 -06:00
|
|
|
new CompressionWebpackPlugin({
|
|
|
|
test: /\.(js|css)$/,
|
|
|
|
filename: '[path][base].gz',
|
|
|
|
}),
|
2022-04-13 10:48:10 -06:00
|
|
|
new MiniCssExtractPlugin({
|
2022-04-19 17:09:35 -06:00
|
|
|
filename: 'assets/app-[fullhash].css',
|
|
|
|
}),
|
|
|
|
new WebpackManifestPlugin({
|
|
|
|
fileName: 'assets/manifest-hash.json',
|
2022-04-13 10:48:10 -06:00
|
|
|
}),
|
|
|
|
new CleanWebpackPlugin(),
|
2022-04-17 21:59:56 -06:00
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env': JSON.stringify(dotenv.parsed),
|
|
|
|
}),
|
2022-04-11 09:25:51 -06:00
|
|
|
],
|
2022-04-13 10:48:10 -06:00
|
|
|
optimization: {
|
|
|
|
minimize: true,
|
|
|
|
minimizer: [
|
|
|
|
new CssMinimizerPlugin(),
|
|
|
|
new TerserPlugin(),
|
|
|
|
],
|
2022-04-19 17:09:35 -06:00
|
|
|
splitChunks: {
|
|
|
|
chunks: 'async',
|
|
|
|
cacheGroups: {
|
|
|
|
vendors: {
|
|
|
|
name: 'vendors',
|
|
|
|
chunks: 'all',
|
|
|
|
reuseExistingChunk: true,
|
|
|
|
priority: 1,
|
|
|
|
filename: 'assets/vendor-[fullhash].js',
|
|
|
|
enforce: true,
|
|
|
|
test (module, chunks){
|
|
|
|
const name = module.nameForCondition && module.nameForCondition();
|
|
|
|
return chunks.name !== 'vendors' && /[\\/]node_modules[\\/]/.test(name);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-04-13 10:48:10 -06:00
|
|
|
},
|
|
|
|
}
|