diff --git a/scripts/minify.ts b/scripts/minify.ts index 46fc9078..72cdba12 100644 --- a/scripts/minify.ts +++ b/scripts/minify.ts @@ -16,6 +16,7 @@ function minifyOptions(debug: boolean): MinifyOptions { global_defs: { 'globalThis.partytownDebug': true, }, + keep_classnames: true, inline: false, join_vars: false, loops: false, @@ -37,6 +38,7 @@ function minifyOptions(debug: boolean): MinifyOptions { global_defs: { 'globalThis.partytownDebug': false, }, + keep_classnames: keepConstructorNames(), ecma: 2018, passes: 2, unsafe_symbols: true, @@ -45,9 +47,17 @@ function minifyOptions(debug: boolean): MinifyOptions { comments: false, ecma: 2018, }, + keep_classnames: keepConstructorNames(), + mangle: { + keep_classnames: keepConstructorNames(), + }, }; } +function keepConstructorNames() { + return /HTMLAnchorElement|HTMLIFrameElement|HTMLScriptElement|HTMLDocument|HTMLElement|Node|Window/; +} + function managlePropsPlugin(): Plugin { const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$'.split(''); const mangleProps: { [key: string]: string } = { diff --git a/tests/platform/document-prod/document-prod.spec.ts b/tests/platform/document-prod/document-prod.spec.ts index ad50000c..e99463f6 100644 --- a/tests/platform/document-prod/document-prod.spec.ts +++ b/tests/platform/document-prod/document-prod.spec.ts @@ -53,4 +53,7 @@ test('document-prod', async ({ page }) => { await expect(testCurrentScriptSrcLocation).toHaveText( '/platform/document-prod/current-script-src.js' ); + + const testDocCstrName = page.locator('#testDocCstrName'); + await expect(testDocCstrName).toHaveText('HTMLDocument'); }); diff --git a/tests/platform/document-prod/index.html b/tests/platform/document-prod/index.html index 474020f4..ddaeaf30 100644 --- a/tests/platform/document-prod/index.html +++ b/tests/platform/document-prod/index.html @@ -292,6 +292,17 @@
+
+
+
+