-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
95 lines (87 loc) · 2.3 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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const merge = require('webpack-merge');
const pug = require('./webpack/pug');
const devserver = require('./webpack/devserver');
const sass = require('./webpack/sass');
const extractCSS = require('./webpack/css.extract');
const images = require('./webpack/images');
const babel = require('./webpack/babel');
const PATHS = {
source: path.join(__dirname, 'src'),
build: path.join(__dirname, 'build')
};
const common = merge([
{
entry: {
"index": PATHS.source + '/main.js',
// "sw": PATHS.source + '/cache_serviceworker.js',
},
output: {
path: PATHS.build,
filename: 'js/[name].js',
},
plugins: [
new HtmlWebpackPlugin({
template: PATHS.source + '/index.pug',
inject: false,
}),
],
},
pug(),
images(),
]);
const dev = {
optimization: {
minimize: true,
},
devtool: "eval",
};
const prod = {
optimization: {
minimize: true,
},
}
const devMode = {
mode: 'development',
plugins: [
new webpack.DefinePlugin({
HOST: JSON.stringify('http://localhost:8002'),
MY_HOST: JSON.stringify('http://localhost:8001'),
HOST_MULTIPLAYER_WS: JSON.stringify('ws://127.0.0.1:8004/game'),
HOST_MULTIPLAYER: JSON.stringify('http://localhost:8004/game'),
}),
]
};
const prodMode = {
mode: 'production',
plugins: [
new webpack.DefinePlugin({
HOST: JSON.stringify('https://api.colors-game.ru'),
MY_HOST: JSON.stringify('https://colors-game.ru'),
HOST_MULTIPLAYER_WS: JSON.stringify('wss://api.colors-game.ru/game'),
HOST_MULTIPLAYER: JSON.stringify('https://api.colors-game.ru/game'),
}),
]
};
module.exports = function (env) {
if (env === 'production') {
return merge([
common,
extractCSS(),
babel(),
prod,
prodMode,
]);
}
if (env === 'development') {
return merge([
common,
devserver(),
sass(),
dev,
devMode,
])
}
};