Skip to content

Commit

Permalink
Don't mangle "initSqlJs" function during minification/optimization
Browse files Browse the repository at this point in the history
The code in sqljs has some custom logic on how the function should be
exported, which I guess breaks the minifier causing it to emit invalid
code when trying to invoke the function from the extension code.
The easiest workaround I found is to exclude the function name from
mangling, which preserves the original name and, when invoked, it
still works.

Fixes #36
  • Loading branch information
danvratil committed Aug 25, 2024
1 parent 00d0b48 commit d3b72f4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"@vscode/test-electron": "^2.4.0",
"copy-webpack-plugin": "^12.0.2",
"eslint": "^8.57.0",
"terser-webpack-plugin": "^5.3.10",
"ts-loader": "^9.5.1",
"typescript": "^5.4.5",
"webpack": "^5.93.0",
Expand Down
16 changes: 15 additions & 1 deletion webpack.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'use strict';

const CopyPlugin = require('copy-webpack-plugin');
const TerserPlugin = require("terser-webpack-plugin");
const path = require('path');

//@ts-check
Expand Down Expand Up @@ -63,6 +64,19 @@ const extensionConfig = {
{ from: 'node_modules/sql.js/dist/sql-wasm.wasm', to: 'sql-wasm.wasm' }
]
})
]
],
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
mangle: {
// don't mangle the "initSqlJs" function, otherwise the whole thing breaks and calling
// it from our code fails with "(0, default.l) is not a function"
reserved: [ "initSqlJs" ]
}
}
})
]
}
};
module.exports = [ extensionConfig ];

0 comments on commit d3b72f4

Please sign in to comment.