132 lines
3.1 KiB
JavaScript
132 lines
3.1 KiB
JavaScript
const HtmlWebPackPlugin = require('html-webpack-plugin')
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin')
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
|
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
|
|
const TerserPlugin = require('terser-webpack-plugin')
|
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
|
|
const dotenv = require('dotenv')
|
|
const webpack = require('webpack')
|
|
|
|
const prod =
|
|
(process.env.NODE_ENV ? process.env.NODE_ENV : '').trim() === 'production'
|
|
const path = require('path')
|
|
|
|
module.exports = () => {
|
|
dotenv.config({
|
|
path: './.env',
|
|
})
|
|
|
|
return {
|
|
entry: './src/index.js',
|
|
output: {
|
|
filename: '[name].[contenthash].js',
|
|
path: path.resolve(__dirname, 'dist'),
|
|
clean: true,
|
|
},
|
|
resolve: {
|
|
extensions: ['.tsx', '.ts', '.js'],
|
|
},
|
|
optimization: {
|
|
runtimeChunk: 'single',
|
|
moduleIds: 'deterministic',
|
|
minimizer: [`...`, new CssMinimizerPlugin()],
|
|
splitChunks: {
|
|
cacheGroups: {
|
|
vendor: {
|
|
test: /[\\/]node_modules[\\/]/,
|
|
name: 'vendors',
|
|
chunks: 'all',
|
|
},
|
|
styles: {
|
|
name: 'styles',
|
|
type: 'css/mini-extract',
|
|
chunks: 'all',
|
|
enforce: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
mode: prod ? 'production' : 'development',
|
|
// Enable sourcemaps for debugging webpack's output.
|
|
devtool: prod ? 'none' : 'eval-source-map',
|
|
devServer: {
|
|
historyApiFallback: true,
|
|
},
|
|
node: {
|
|
global: true,
|
|
},
|
|
plugins: [
|
|
new webpack.DefinePlugin({
|
|
'process.env': JSON.stringify(process.env),
|
|
}),
|
|
new HtmlWebPackPlugin({
|
|
template: './src/index.html',
|
|
filename: './index.html',
|
|
}),
|
|
new CopyWebpackPlugin({
|
|
patterns: [
|
|
{
|
|
from: 'src/static/images',
|
|
to: 'static/images',
|
|
},
|
|
],
|
|
}),
|
|
new MiniCssExtractPlugin({
|
|
filename: '[name].css',
|
|
}),
|
|
new CleanWebpackPlugin(),
|
|
],
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.js$/,
|
|
exclude: /node_modules/,
|
|
use: {
|
|
loader: 'babel-loader',
|
|
},
|
|
},
|
|
{
|
|
test: /\.tsx?$/,
|
|
use: 'ts-loader',
|
|
exclude: /node_modules/,
|
|
},
|
|
{
|
|
test: /\.svg$/,
|
|
exclude: /node_modules/,
|
|
use: ['@svgr/webpack'],
|
|
},
|
|
{
|
|
test: /\.css$/i,
|
|
use: [MiniCssExtractPlugin.loader, 'css-loader'],
|
|
},
|
|
{
|
|
test: /\.scss$/,
|
|
use: [
|
|
{
|
|
loader: MiniCssExtractPlugin.loader,
|
|
options: {
|
|
publicPath: '../',
|
|
},
|
|
},
|
|
'css-loader',
|
|
'sass-loader',
|
|
],
|
|
},
|
|
{
|
|
test: /\.(gif|png|jpe?g)$/i,
|
|
use: [
|
|
'file-loader',
|
|
{
|
|
loader: 'image-webpack-loader',
|
|
options: {
|
|
bypassOnDebug: true,
|
|
disable: true,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
}
|
|
}
|