Skip to content

Commit 1703c1a

Browse files
committed
updating webpack.dev for local dev
1 parent d2ed000 commit 1703c1a

File tree

2 files changed

+60
-25
lines changed

2 files changed

+60
-25
lines changed

web/bundler/webpack.common.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,41 @@
1+
// Import necessary plugins and modules
12
const CopyWebpackPlugin = require('copy-webpack-plugin');
23
const HtmlWebpackPlugin = require('html-webpack-plugin');
34
const MiniCSSExtractPlugin = require('mini-css-extract-plugin');
45
const path = require('path');
56

7+
// Export the webpack configuration
68
module.exports = {
9+
// Entry point for the application, the main JavaScript file
710
entry: path.resolve(__dirname, '../src/script.js'),
11+
12+
// Output configuration for the bundled files
813
output: {
914
filename: 'bundle.[contenthash].js',
1015
path: path.resolve(__dirname, '../dist'),
1116
},
17+
18+
// Source map generation for better debugging
1219
devtool: 'source-map',
20+
21+
// Array of plugins to enhance the webpack build process
1322
plugins: [
23+
// CopyWebpackPlugin for copying static assets to the 'dist' directory
1424
new CopyWebpackPlugin({
15-
patterns: [{from: path.resolve(__dirname, '../static')}],
25+
patterns: [{ from: path.resolve(__dirname, '../static') }],
1626
}),
27+
28+
// HtmlWebpackPlugin for generating an HTML file from a template
1729
new HtmlWebpackPlugin({
1830
template: path.resolve(__dirname, '../src/index.html'),
1931
minify: true,
2032
}),
33+
34+
// MiniCSSExtractPlugin for extracting CSS into separate files
2135
new MiniCSSExtractPlugin(),
2236
],
37+
38+
// Module configuration for defining how different file types should be processed
2339
module: {
2440
rules: [
2541
// HTML
@@ -75,11 +91,11 @@ module.exports = {
7591
loader: 'file-loader',
7692
options: {
7793
name: '[name].[ext]',
78-
outputPath: 'assets/menu/'
79-
}
80-
}
81-
]
82-
}
94+
outputPath: 'assets/menu/',
95+
},
96+
},
97+
],
98+
},
8399
],
84100
},
85101
};

web/bundler/webpack.dev.js

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,53 @@
1+
const path = require("path");
12
const { merge } = require("webpack-merge");
2-
const commonConfiguration = require("./webpack.common.js");
33
const portFinderSync = require("portfinder-sync");
4-
5-
const infoColor = (_message) => {
6-
return `\u001b[1m\u001b[34m${_message}\u001b[39m\u001b[22m`;
7-
};
4+
const commonConfiguration = require("./webpack.common.js");
85

96
module.exports = merge(commonConfiguration, {
107
mode: "development",
8+
119
devServer: {
1210
host: "localhost",
1311
port: portFinderSync.getPort(8080),
14-
contentBase: "./dist",
15-
watchContentBase: true,
12+
static: [
13+
{
14+
directory: path.resolve(__dirname, "dist"),
15+
watch: true,
16+
},
17+
{
18+
directory: path.resolve(__dirname, "static"),
19+
staticOptions: {},
20+
publicPath: "/static-public-path/",
21+
serveIndex: true,
22+
watch: true,
23+
},
24+
],
1625
proxy: {
17-
"/socket.io": { target: "ws://localhost:3000" },
18-
"/api": { target: "ws://localhost:8080" },
26+
"/socket.io": { target: "http://localhost:3000", ws: true },
27+
"/api": { target: "http://localhost:8080", ws: true },
1928
},
2029
open: true,
2130
https: false,
22-
useLocalIp: false,
23-
disableHostCheck: true,
24-
overlay: true,
25-
noInfo: true,
26-
after: function (app, server, compiler) {
27-
const port = server.options.port;
28-
const https = server.options.https ? "s" : "";
29-
const domain = `http${https}://localhost:${port}`;
30-
31-
console.log(`Project running at:\n - ${infoColor(domain)}`);
31+
allowedHosts: "all",
32+
onAfterSetupMiddleware: function (devServer) {
33+
devServer.app.get("/some/path", function (req, res) {
34+
res.json({ custom: "response" });
35+
});
36+
},
37+
client: {
38+
logging: "info",
39+
overlay: {
40+
errors: true,
41+
warnings: true,
42+
},
43+
progress: true,
44+
reconnect: true,
45+
webSocketTransport: "ws",
46+
webSocketURL: {
47+
hostname: "localhost",
48+
pathname: "/ws",
49+
port: 8080,
50+
},
3251
},
3352
},
3453
});

0 commit comments

Comments
 (0)