From d3b72f4ffafce71ce2c42f808d0903e2fff9f92c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Vr=C3=A1til?= Date: Sun, 25 Aug 2024 11:14:35 +0200 Subject: [PATCH] Don't mangle "initSqlJs" function during minification/optimization 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 --- package-lock.json | 2 ++ package.json | 1 + webpack.config.cjs | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index b1bc072..6d6c7d4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,6 +29,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", @@ -4397,6 +4398,7 @@ "resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-5.3.10.tgz", "integrity": "sha512-BKFPWlPDndPs+NGGCr1U59t0XScL5317Y0UReNrHaw9/FwhPENlq6bfgs+4yPfyP51vqC1bQ4rp1EfXW5ZSH9w==", "dev": true, + "license": "MIT", "dependencies": { "@jridgewell/trace-mapping": "^0.3.20", "jest-worker": "^27.4.5", diff --git a/package.json b/package.json index d49f518..39f47e8 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/webpack.config.cjs b/webpack.config.cjs index 1c392a0..672d4f9 100644 --- a/webpack.config.cjs +++ b/webpack.config.cjs @@ -7,6 +7,7 @@ 'use strict'; const CopyPlugin = require('copy-webpack-plugin'); +const TerserPlugin = require("terser-webpack-plugin"); const path = require('path'); //@ts-check @@ -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 ]; \ No newline at end of file