-
Notifications
You must be signed in to change notification settings - Fork 23
/
webpack.config.js
94 lines (93 loc) · 2.65 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
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
93
94
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
/*
We include the style sheets and the UIKit library into each entry point.
Alternatively, these could be included in the corresponding "main" .ts/.js files.
*/
entry: {
site_a: {
import: ["./src/entry_site_a.ts", "./src/css/entry_site_a.less", "uikit"],
},
site_b: {
import: ["./src/entry_site_b.ts", "./src/css/entry_site_b.less", "uikit"],
},
main: {
import: ["./src/entry_main.ts", "./src/css/entry_main.less", "uikit"],
},
},
/*
Output is stored in the `dist` folder and contains the "content hash"
to ensure two different versions of the same file cannot be confused
for each other.
*/
output: {
clean: true,
filename: "[name].[hash].bundle.js",
path: path.resolve(__dirname, "dist"), // must be an absolute path
},
/* Dist is also where we want to start the development web server. */
devServer: {
static: "./dist",
},
module: {
rules: [
/* Use Babel to convert JavaScript/TypeScript files. */
{
test: /\.(js|ts|jsx|tsx)$/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"],
},
},
exclude: /node_modules/,
},
/* Use LESS, and then load the result with normal CSS loader. */
{
test: /\.less$/i,
use: ["style-loader", "css-loader", "less-loader"],
},
/*
Load images: "importing" an image will copy it to the output
and return the corresponding URL.
*/
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: "asset/resource",
},
/*
Load HTML files: You can import HTML files, which will simply
return the content as text.
*/
{
test: /\.html$/i,
loader: "html-loader",
},
],
},
plugins: [
// Generates the default index.html
new HtmlWebpackPlugin({
title: "PV252 Example project",
// If we don't need (or want) to use all entry points,
// we can use `chunks` to specify which entry point to use.
chunks: ["main"],
filename: "index.html",
template: "./src/html/index.template.ejs",
}),
// Generate separate HTML files for the two sites.
new HtmlWebpackPlugin({
title: "Site A",
chunks: ["site_a"],
filename: "site_a.html",
template: "./src/html/site_a.template.ejs",
}),
new HtmlWebpackPlugin({
title: "Site B",
chunks: ["site_b"],
filename: "site_b.html",
template: "./src/html/site_b.template.ejs",
}),
],
};