-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
82 lines (74 loc) · 1.72 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
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 SERVER_URL = /http:\/\/localhost:9000/g
const FRONTEND_PORT = 3000
const INDEX_HTML_PATH = './frontend/index.html'
const INDEX_JS_PATH = './frontend/index.js'
const DIST_FOLDER = 'dist'
const BUNDLE_FILE = 'index.js'
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,
},
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,
exclude: /node_modules/,
use: [
STYLE_LOADER,
CSS_LOADER,
],
},
],
},
}
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