-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathwebpack.config.js
executable file
·108 lines (99 loc) · 2.4 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
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-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 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 DIST_PATH = 'dist'
const PUBLIC_PATH = IS_DEV ? '/' : './'
const INDEX_HTML_PATH = './frontend/index.html'
const INDEX_JS_PATH = './frontend/index.js'
const AUDIO_PATH = 'audio/'
const JS_NAME = IS_DEV ? 'index.js' : 'index.[contenthash].js'
const CSS_NAME = IS_DEV ? 'style.css' : 'style.[contenthash].css'
const MP3_NAME = '[name].[ext]'
const SOURCE_MAP = IS_DEV ? 'source-map' : false
const config = {
entry: INDEX_JS_PATH,
mode: ENV,
output: {
filename: JS_NAME,
publicPath: PUBLIC_PATH,
path: path.resolve(__dirname, DIST_PATH),
},
devtool: SOURCE_MAP,
plugins: [
new HtmlWebpackPlugin({
template: INDEX_HTML_PATH,
}),
new MiniCssExtractPlugin({
filename: CSS_NAME,
}),
],
devServer: {
static: path.join(__dirname, DIST_PATH),
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: [
MiniCssExtractPlugin.loader,
CSS_LOADER,
],
},
{
test: /\.(png|jpe?g|gif|svg)$/i,
type: 'asset/resource',
},
{
test: /\.mp3$/,
use: [
{
loader: FILE_LOADER,
options: {
name: MP3_NAME,
outputPath: AUDIO_PATH,
publicPath: AUDIO_PATH,
},
},
],
},
],
},
}
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