-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.dev.config.js
92 lines (91 loc) · 2.61 KB
/
webpack.dev.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
const path = require("path");
const { CleanWebpackPlugin } = require("clean-webpack-plugin"); //plugin for cleaning the output folder (in this project dist folder) before build the webpack output
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
entry: {
"hello-world": "./src/hello-world.js",
kebon: "./src/kebon.js",
},
output: {
filename: "[name].bundle.js", // for dynamic name file every changes / update occur in the file so browser will download the new one useful for case caching
path: path.resolve(__dirname, "./dist"),
publicPath: "",
},
mode: "development",
devServer: {
port: 9000,
static: {
directory: path.resolve(__dirname, "./dist"),
},
devMiddleware: {
index: "index.html",
writeToDisk: true,
},
},
module: {
rules: [
{
test: /\.(png|jpg)$/,
type: "asset",
parser: {
dataUrlCondition: {
maxSize: 3 * 1024, // 3 kilobytes
},
},
},
{
test: /\.txt/,
type: "asset/source",
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
},
{
test: /\.scss$/,
use: ["style-loader", "css-loader", "sass-loader"], //First it will invoke sass-loader, which will convert our sass to css.
//Then it will invoke css-loader, which will take that converted css and convert it to the
//And only then Webpack will invoke style-loader, which will create style tags inside our html page and put css into it
},
{
test: /\.js$/,
exclude: /node_modules/, // this rule will not implement on node modules folder
use: {
loader: "babel-loader",
options: {
presets: ["@babel/env"],
plugins: ["@babel/plugin-proposal-class-properties"],
},
},
},
{
test: /\.hbs$/,
use: ["handlebars-loader"],
},
],
},
plugins: [
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [
"**/*", //default value if u not modified it
path.join(process.cwd(), "build/**/*"),
],
}), //can clean multiple folder
new HtmlWebpackPlugin({
filename: "hello-world.html",
chunks: ["hello-world"],
title: "Hello world",
description: "some description",
template: "src/page-template.hbs",
minify: false,
}),
new HtmlWebpackPlugin({
filename: "kebon.html",
chunks: ["kebon"],
title: "kEBON Title",
description: "kebon",
template: "src/page-template.hbs",
minify: false,
}),
],
};