-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.test.ts
More file actions
91 lines (83 loc) · 2.04 KB
/
Copy pathwebpack.test.ts
File metadata and controls
91 lines (83 loc) · 2.04 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
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
import path from "path"
import webpack from "webpack"
import HtmlWebpackPlugin from "html-webpack-plugin"
import MiniCssExtractPlugin from "mini-css-extract-plugin"
import { CleanWebpackPlugin } from "clean-webpack-plugin"
import publiEntries from "./publicEntries"
interface IAppConfigEntries {
title: string
filename: string
template: string
chunks: string[]
}
type IPlugins = (CleanWebpackPlugin | MiniCssExtractPlugin | HtmlWebpackPlugin)[]
const entryGroup: IAppConfigEntries[] = Object.keys(publiEntries).map((key) => ({
title: key,
filename: `${key}.ejs`,
template: `${key}.ejs`,
chunks: [key]
}))
const plugins: IPlugins = [
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: "[name].css"
})
]
Object.values(entryGroup).forEach((entryInfo, _entryName) => {
plugins.push(
new HtmlWebpackPlugin({
title: entryInfo.title,
filename: path.join(__dirname, "./views/" + entryInfo.filename),
template: "!!raw-loader!./src/frontend/templates/" + entryInfo.template,
chunks: entryInfo.chunks,
publicPath: "/bundle",
chunksSortMode: "manual",
inject: "head",
scriptLoading: "defer"
})
)
})
const entry = {
sw: { import: "./src/frontend/scripts/sw.ts", filename: "../sw.js" },
...publiEntries
}
const config: webpack.Configuration = {
mode: "production",
entry,
output: {
path: path.resolve(__dirname, "public/bundle"),
filename: "[name].js",
iife: false,
clean: true
},
plugins,
resolve: {
extensions: [".ts", ".js", ".scss"]
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.ts$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-typescript"]
}
}
},
{
test: /\.s[ac]ss$/i,
use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"]
}
]
}
}
export default config