-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
116 lines (114 loc) · 2.38 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import EjsWebpackPlugin from '@joy9001/ejs-webpack5-plugin'
import dotenv from 'dotenv'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import path from 'path'
import TerserPlugin from 'terser-webpack-plugin'
import webpack from 'webpack'
dotenv.config()
export default {
target: 'web',
node: {
global: true,
},
mode: process.env.NODE_ENV === 'development' ? 'development' : 'production',
entry: {
chat: './client/index/index-chat.js',
login: './client/index/index-login.js',
register: './client/index/index-register.js',
base: './client/index/index-base.js',
},
output: {
filename: '[name].[contenthash].js',
path: path.resolve('./client/dist'),
clean: true,
publicPath: '/',
},
resolve: {
fallback: {
fs: false,
os: false,
path: false,
crypto: false,
stream: false,
vm: false,
},
},
devtool: process.env.NODE_ENV === 'development' ? 'source-map' : false,
module: {
rules: [
{
test: /\.js$/i,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
},
{
test: /\.ejs$/,
use: {
loader: 'ejs',
},
},
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
},
{
test: /\.(png|svg|jpg|jpeg|gif|ico)$/i,
type: 'asset/resource',
},
],
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
exclude: /\/node_modules/,
extractComments: false,
terserOptions: {
format: {
comments: false,
},
},
}),
],
},
plugins: [
new webpack.EnvironmentPlugin(['DOMAIN', 'PORT']),
new EjsWebpackPlugin({
context:
process.env.NODE_ENV === 'development' ? import.meta.dirname : new URL('.', import.meta.url).pathname,
entry: {
'./client/views/chat.ejs': {
js: ['chat'],
css: ['chat'],
output: './client/views/dist',
},
'./client/views/login.ejs': {
js: ['login'],
css: ['base'],
output: './client/views/dist',
},
'./client/views/register.ejs': {
js: ['register'],
css: ['base'],
output: './client/views/dist',
},
'./client/views/404.ejs': {
css: ['chat'],
output: './client/views/dist',
},
},
}),
new MiniCssExtractPlugin({
filename: 'styles/[name].[contenthash].css',
}),
],
}