-
Notifications
You must be signed in to change notification settings - Fork 55
/
webpack.config.js
executable file
·101 lines (93 loc) · 2.12 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
const HtmlWebpackPlugin = require('html-webpack-plugin')
const path = require('path')
const DEVELOPMENT = 'development'
const ENV = process.env.NODE_ENV || DEVELOPMENT
const IS_DEV = ENV === DEVELOPMENT
const HTML_LOADER = 'html-loader'
const STYLE_LOADER = 'style-loader'
const CSS_LOADER = 'css-loader'
const BABEL_LOADER = 'babel-loader'
const STRING_REPLACE_LOADER = 'string-replace-loader'
const FILE_LOADER = 'file-loader'
const SERVER_URL = /http:\/\/localhost:9009/g
const FRONTEND_PORT = 3003
const INDEX_HTML_PATH = './frontend/index.html'
const INDEX_JS_PATH = './frontend/index.js'
const DIST_FOLDER = 'dist'
const BUNDLE_FILE = 'index.js'
const AUDIO = 'audio/'
const SOURCE_MAP = IS_DEV ? 'source-map' : false
const config = {
entry: INDEX_JS_PATH,
mode: ENV,
output: {
filename: BUNDLE_FILE,
publicPath: '/',
path: path.resolve(__dirname, DIST_FOLDER),
},
devtool: SOURCE_MAP,
plugins: [
new HtmlWebpackPlugin({
template: INDEX_HTML_PATH,
}),
],
devServer: {
static: path.join(__dirname, DIST_FOLDER),
historyApiFallback: true,
compress: true,
port: FRONTEND_PORT,
client: { logging: 'none' },
},
module: {
rules: [
{
test: /\.html$/i,
exclude: /node_modules/,
use: { loader: HTML_LOADER }
},
{
test: /\.m?js$/,
exclude: /node_modules/,
use: { loader: BABEL_LOADER },
},
{
test: /\.css$/i,
use: [
STYLE_LOADER,
CSS_LOADER,
],
},
{
test: /\.(png|jpe?g|gif|svg)$/i,
type: 'asset/resource',
},
{
test: /\.mp3$/,
use: [
{
loader: FILE_LOADER,
options: {
name: '[name].[ext]',
outputPath: AUDIO,
publicPath: AUDIO,
},
},
],
},
],
},
}
if (!IS_DEV) {
config.module.rules.push({
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: STRING_REPLACE_LOADER,
options: {
search: SERVER_URL,
replace: '',
},
},
})
}
module.exports = config