-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
56 lines (54 loc) · 2.03 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
// webpack.config.js
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { watch } = require("fs");
module.exports = {
mode: "production", // mode can be development or production
entry: "./src/index.js", // define entry point
output: {
filename: "main.js", // all .js material is gonna go into this file
path: path.resolve(__dirname, "dist"), // all other files will be named main.xxx and be placed in ./dist
clean: true, // It will empty the output directory first before bundling the files into it
},
// 13 to 15: HOW TO SET UP WEBPACK DEV SERVER
// • Install webpack-de server (npm install --save-dev webpack-dev-server)
devtool: "eval-source-map", // • Create source map
devServer: { // • Tells the webserver
watchFiles: ["./src/template.html"], // which file to watch (http://localhost:8080/'s homepage)
},
plugins: [ //ADD HTML HANDLER (MUST HAVE BEEN INSTALLED `npm install html-webpack-plugin`)
new HtmlWebpackPlugin({
template: "./src/template.html", //Tell what the template is going to be
}),
],
module: {
rules: [//TELLS HOW TO RECOGNISE WHAT FILES
{//FOR LOADING CSS FILES
test: /\.css$/i, // the extansion(s) the loader will look for
use: ["style-loader", "css-loader"],
},
{//FOR LOADING HTML FILES
test: /\.html$/i,
loader: "html-loader",
},
{ //FOR LOADING IMAGES
test: /\.(png|svg|jpg|jpeg|gif|webp)$/i,
type: "asset/resource",
},
{ //FOR LOADING FONTS
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
},
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader']
},
],
},
performance: {
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000,
},
watch: true
};