File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ import { fileURLToPath } from "url";
99const __filename = fileURLToPath ( import . meta. url ) ;
1010const __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+
3351export 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 }
You can’t perform that action at this time.
0 commit comments