Skip to content

Commit ee2acdc

Browse files
committed
maint(Build): Directly build the modernizr bundle.
Do not use an webpack entry to build the modernizr bundle with an webpack runtime overhead. Instead, build it directly but abusing the webpack CopyPlugin transform mechanism. We could also build the modernizr bundle from the Makefile but that wouldn't provide the file when watching or when running webpack-dev-server.
1 parent e1fd8de commit ee2acdc

File tree

3 files changed

+36
-22
lines changed

3 files changed

+36
-22
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
"@patternslib/pat-tiptap": "^4.7.2",
4545
"@patternslib/pat-upload": "^3.1.1",
4646
"copy-webpack-plugin": "^11.0.0",
47-
"pegjs": "0.11.0-master.b7b87ea",
48-
"webpack-modernizr-loader": "^5.0.0"
47+
"modernizr": "^3.12.0",
48+
"pegjs": "0.11.0-master.b7b87ea"
4949
},
5050
"resolutions": {
5151
"jquery": "3.6.2"

src/modernizr.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

webpack/webpack.config.js

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ const mf_config = require("@patternslib/dev/webpack/webpack.mf");
55
const package_json = require("../package.json");
66
const path = require("path");
77
const webpack_config = require("@patternslib/dev/webpack/webpack.config").config;
8+
const modernizr_config = require("../.modernizrrc.js");
9+
const modernizr = require("modernizr");
810

911
module.exports = () => {
1012
let config = {
1113
entry: {
1214
"bundle.min": path.resolve(__dirname, "../src/index.js"),
13-
"modernizr.min": path.resolve(__dirname, "../src/modernizr.js"),
1415
},
1516
};
1617

@@ -21,15 +22,6 @@ module.exports = () => {
2122

2223
config.output.path = path.resolve(__dirname, "../dist/");
2324

24-
// Modernizr
25-
config.module.rules.push({
26-
test: /\.modernizrrc\.js$/,
27-
loader: "webpack-modernizr-loader",
28-
});
29-
config.resolve.alias = {
30-
modernizr$: path.resolve(__dirname, "../.modernizrrc.js"),
31-
};
32-
3325
// Module federation
3426
config.plugins.push(
3527
mf_config({
@@ -50,14 +42,41 @@ module.exports = () => {
5042
})
5143
);
5244

53-
// BBB polyfills not used anymore.
54-
// TODO: Remove for next major version.
55-
// Polyfills
45+
// Copy static files
5646
config.plugins.push(
57-
// Copy polyfills loader to the output path.
5847
new CopyPlugin({
5948
patterns: [
60-
{ from: path.resolve(__dirname, "../src/polyfills-loader.js"), }, // prettier-ignore
49+
// Copy polyfills loader to the output path.
50+
// TODO: Polyfills not used anymore, remove for next major version.
51+
{ from: path.resolve(__dirname, "../src/polyfills-loader.js") },
52+
53+
// Build and copy Modernizr.
54+
// We're abusing the CopyPlugin transform method here to build
55+
// a Modernizr bundle using the modernizr config. The input
56+
// file does not matter and could be anything - we're using the
57+
// modernizr config itself.
58+
// Why building modernizr here and not in the Makefile?
59+
// Because we want webpack-dev-server also to serve it.
60+
{
61+
from: path.resolve(__dirname, "../.modernizrrc.js"),
62+
to: "[path]modernizr.min.js",
63+
transform: {
64+
transformer: () => {
65+
return new Promise((resolve) => {
66+
modernizr.build(
67+
{
68+
...modernizr_config,
69+
minify: process.env.NODE_ENV === "production",
70+
},
71+
(result) => {
72+
resolve(result);
73+
}
74+
);
75+
});
76+
},
77+
cache: true,
78+
},
79+
},
6180
],
6281
})
6382
);

0 commit comments

Comments
 (0)