Skip to content

Commit 9731cea

Browse files
committed
Remove use strict statement from final QML bundle
1 parent 911ca91 commit 9731cea

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

glean/webpack.config.qt.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { fileURLToPath } from "url";
99
const __filename = fileURLToPath(import.meta.url);
1010
const __dirname = dirname(__filename);
1111

12+
const OUTPUT = "glean.lib.js";
13+
1214
/**
1315
* Hacky plugin that removes ".js" extensions from imports before resolving.
1416
*
@@ -30,6 +32,22 @@ class TsResolvePlugin {
3032
}
3133
}
3234

35+
/**
36+
* Plugin to remove the "use strict" statement added by Webpack before emmiting final bundle.
37+
*
38+
* Context on why this is necessary: https://github.com/101arrowz/fflate/pull/75#issuecomment-865016941,
39+
* tl;dr; "use strict" makes accessing a negative index throw an error in QML,
40+
* and not anywhere else.
41+
*/
42+
class RemoveUseStrictPlugin {
43+
apply(compiler) {
44+
compiler.hooks.shouldEmit.tap("RemoveUseStrictPlugin", compilation => {
45+
compilation.assets[OUTPUT]._value = compilation.assets[OUTPUT]._value.replace("\"use strict\";", "");
46+
return true;
47+
});
48+
}
49+
}
50+
3351
export default {
3452
entry: "./src/index/qt.ts",
3553
mode: "production",
@@ -60,9 +78,12 @@ export default {
6078
new TsResolvePlugin()
6179
]
6280
},
81+
plugins: [
82+
new RemoveUseStrictPlugin(),
83+
],
6384
output: {
6485
path: path.resolve(__dirname, "dist/qt/org/mozilla/Glean"),
65-
filename: "glean.lib.js",
86+
filename: OUTPUT,
6687
libraryTarget: "var",
6788
library: "Glean",
6889
}

0 commit comments

Comments
 (0)