Skip to content

Commit 33d5eaf

Browse files
committed
build: enable mangling of privates
1 parent 2cdb2a9 commit 33d5eaf

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

packages/alphatab/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export default defineConfig(({ mode }) => {
8585
lib.entry['alphaTab.core'] = path.resolve(__dirname, 'src/alphaTab.core.ts');
8686
lib.entry['alphaTab.worker'] = path.resolve(__dirname, 'src/alphaTab.worker.ts');
8787
lib.entry['alphaTab.worklet'] = path.resolve(__dirname, 'src/alphaTab.worklet.ts');
88-
88+
8989
for (const output of config.build!.rollupOptions!.output as OutputOptions[]) {
9090
const isMin = (output.entryFileNames as string).includes('.min');
9191
(output.plugins as Plugin[]).push(adjustScriptPathsPlugin(isMin));

packages/tooling/src/vite.plugin.dts.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export default function generateDts(root: string, entryFile: string, outputFilen
2626
},
2727
dtsRollup: {
2828
enabled: true,
29-
publicTrimmedFilePath: outputFile
29+
publicTrimmedFilePath: outputFile,
30+
omitTrimmingComments: true
3031
}
3132
}
3233
});

packages/tooling/src/vite.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
import fs from 'node:fs';
22
import path from 'node:path';
33
import url from 'node:url';
4-
import terser from '@rollup/plugin-terser';
4+
import terser, {type Options as TerserOptions } from '@rollup/plugin-terser';
55
import typescript, { type RollupTypescriptOptions } from '@rollup/plugin-typescript';
66
import type { OutputChunk, OutputOptions } from 'rollup';
77
import license from 'rollup-plugin-license';
88
import ts from 'typescript';
99
import type { LibraryOptions, UserConfig } from 'vite';
1010
import generateDts from './vite.plugin.dts.ts';
1111

12+
const terserOptions: TerserOptions = {
13+
mangle: {
14+
properties: {
15+
regex: /^_/
16+
}
17+
}
18+
};
19+
1220
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
1321

1422
let repositoryRoot = __dirname;
@@ -128,7 +136,7 @@ export function umd(
128136
dir: 'dist/',
129137
format: 'umd',
130138
name: name,
131-
plugins: [terser()],
139+
plugins: [terser(terserOptions)],
132140
entryFileNames: '[name].min.js',
133141
chunkFileNames: '[name].min.js'
134142
});
@@ -213,15 +221,15 @@ export function esm(
213221
},
214222
dir: 'dist/',
215223
format: 'es',
216-
plugins: [terser()],
224+
plugins: [terser(terserOptions)],
217225
entryFileNames: '[name].min.mjs',
218226
chunkFileNames: '[name].min.mjs'
219227
});
220228
}
221229
}
222230

223231
export function dtsPathsTransformer(mapping: Record<string, string>) {
224-
const mapPath = (filePath, input: string): string | undefined => {
232+
const mapPath = (filePath:string, input: string): string | undefined => {
225233
for (const [k, v] of Object.entries(mapping)) {
226234
if (input.startsWith(k)) {
227235
const absoluteFile = path.resolve(v, input.substring(k.length));
@@ -233,7 +241,7 @@ export function dtsPathsTransformer(mapping: Record<string, string>) {
233241

234242
return (context: ts.TransformationContext) => {
235243
return (source: ts.SourceFile | ts.Bundle) => {
236-
const sourceFilePath = ts.isSourceFile(source) ? source.fileName : source.sourceFiles[0];
244+
const sourceFilePath = ts.isSourceFile(source) ? source.fileName : source.sourceFiles[0].fileName;
237245

238246
const visitor = (node: ts.Node) => {
239247
if (ts.isExportDeclaration(node) && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {

0 commit comments

Comments
 (0)