-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-webpack.sh
More file actions
executable file
·61 lines (53 loc) · 1.23 KB
/
setup-webpack.sh
File metadata and controls
executable file
·61 lines (53 loc) · 1.23 KB
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
#!/bin/bash
# Exit on errors
set -e
# Initialize npm project
npm init -y
# Install Webpack and related dependencies
npm install -D webpack webpack-cli webpack-dev-server html-webpack-plugin style-loader css-loader html-loader
# Create the source directory and files
mkdir -p src && touch src/index.js src/main.html src/styles.css
# Create the Webpack configuration file
cat <<EOL > webpack.config.js
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
mode: "development",
entry: "./src/index.js",
output: {
filename: "main.js",
path: path.resolve(__dirname, "dist"),
clean: true,
},
devtool: "eval-source-map",
devServer: {
static: path.resolve(__dirname, "dist"),
watchFiles: ["./src/main.html"],
},
plugins: [
new HtmlWebpackPlugin({
template: "./src/main.html",
}),
],
module: {
rules: [
{
test: /\.css$/i,
use: ["style-loader", "css-loader"],
},
{
test: /\.html$/i,
loader: "html-loader",
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: "asset/resource",
},
],
},
};
EOL
# Run Webpack
npx webpack
# Start the development server
npx webpack serve