forked from fontra/fontra
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.cjs
More file actions
68 lines (67 loc) · 2.68 KB
/
webpack.config.cjs
File metadata and controls
68 lines (67 loc) · 2.68 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
const HtmlBundlerPlugin = require("html-bundler-webpack-plugin");
const path = require("path");
module.exports = (_env, argv) => {
return import("@fontra/core/webpack-base.js").then(({ makeConfig }) => {
return makeConfig({
home: __dirname,
destination: path.resolve(__dirname, "src", "fontra", "client"),
views: [
// Unfortunately we run into version compatibility problems if we get
// webpack-base.js to provide its own HtmlBundlerPlugin, so we have
// to provide our own.
new HtmlBundlerPlugin({
entry: {
landing: require.resolve("@fontra/projectmanager-filesystem/landing.html"),
applicationsettings: require.resolve(
"@fontra/views-applicationsettings/applicationsettings.html"
),
editor: require.resolve("@fontra/views-editor/editor.html"),
fontinfo: require.resolve("@fontra/views-fontinfo/fontinfo.html"),
fontoverview: require.resolve(
"@fontra/views-fontoverview/fontoverview.html"
),
},
js: {
// JS output filename, relative to `output.path` Webpack option
filename: "js/[name].[contenthash:8].js",
chunkFilename: "[name].chunk.js",
},
css: {
// CSS output filename, relative to `output.path` Webpack option
filename: "css/[name].[contenthash:8].css",
},
}),
],
production: argv.mode === "production",
custom: {
extends: require.resolve("@fontra/core/webpack.config.cjs"), // This does the copy of core assets
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
test: /\.(js|ts)$/, // <= IMPORTANT: split only script files
chunks: "all", // <= DEFINE it here only
name({ context }, chunks, groupName) {
// save split chunks of the node module under package name
if (/[\\/]node_modules[\\/]/.test(context)) {
const moduleName = context
.match(/[\\/]node_modules[\\/](.*?)(?:[\\/]|$)/)[1]
.replace("@", "");
return `npm.${moduleName}`;
} else if (/[\\/]src-js[\\/]/.test(context)) {
return context
.match(/[\\/]src-js[\\/](.*?)(?:[\\/]|$)/)[1]
.replace("@", "");
// return "fontra";
}
// save split chunks of the application
return groupName;
},
},
},
},
},
},
});
});
};