-
Notifications
You must be signed in to change notification settings - Fork 10
/
webpack.dev.js
67 lines (64 loc) · 1.98 KB
/
webpack.dev.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
const path = require("path");
const merge = require("webpack-merge");
const ReactRefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin");
const common = require("./webpack.common.js");
require("dotenv").config({
path: path.join(__dirname, ".env"),
});
// Exemples de config :
//
// WEBPACK_SERVER_HOST : localhost:5000
// WEBPACK_SERVER_PORT : aucun
// Le serveur écoute sur le port 5000 et les liens générés pour les bundles utilisent localhost:5000
//
// WEBPACK_SERVER_HOST : agir.local
// WEBPACK_SERVER_PORT : 4000
// Le serveur écoute sur le port 4000 et les liens générés pour les bundles utilisent agir.local (sans numéro de port)
const serverName = process.env.WEBPACK_SERVER_HOST || "agir.local:3000";
const port = +process.env.WEBPACK_SERVER_PORT || +serverName.split(":")[1];
module.exports = merge.merge(common("dev"), {
mode: "development",
devtool: "eval-cheap-module-source-map",
output: {
publicPath: `http://${serverName}/`,
devtoolModuleFilenameTemplate: "webpack://[absolute-resource-path]",
filename: "[name].js",
pathinfo: false,
},
optimization: {
removeAvailableModules: false,
removeEmptyChunks: false,
runtimeChunk: "single",
splitChunks: false,
moduleIds: "named",
chunkIds: "named",
emitOnErrors: false,
},
watchOptions: {
poll: 1000,
ignored: /theme\.scss$/,
},
devServer: {
hot: "only",
host: serverName === "localhost" ? "localhost" : "0.0.0.0",
port: port,
devMiddleware: {
publicPath: `http://${serverName}/`,
writeToDisk: true,
},
client: {
webSocketURL: `auto://${serverName}`,
},
static: {
directory: path.join(__dirname, "/assets/"),
watch: false,
},
headers: {
"Access-Control-Allow-Origin": "*",
},
allowedHosts: process.env.ALLOWED_HOSTS
? process.env.ALLOWED_HOSTS.split(",").map((host) => host.trim())
: ["agir.local", ".ap.lfi.site"],
},
plugins: [new ReactRefreshWebpackPlugin()],
});