Skip to content

Commit 0381b3a

Browse files
authored
fix(webpack): Prevent worker chunks using global library settings (#2301)
2 parents 7a3395e + 93cc2f4 commit 0381b3a

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/webpack/AlphaTabAudioWorklet.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ export function configureAudioWorklet(
5050
entryOptions: {
5151
chunkLoading: false,
5252
wasmLoading: false,
53-
runtime: runtime
53+
runtime: runtime,
54+
library: {
55+
// prevent any built-in/default library settings
56+
// to be active for this chunk
57+
type: 'at-worklet'
58+
}
5459
}
5560
});
5661

src/webpack/AlphaTabWebWorker.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ export function configureWebWorker(
5252
entryOptions: {
5353
chunkLoading: 'import-scripts',
5454
wasmLoading: false,
55-
runtime: runtime
55+
runtime: runtime,
56+
library: {
57+
// prevent any built-in/default library settings
58+
// to be active for this chunk
59+
type: 'at-worker'
60+
}
5661
}
5762
});
5863

test/bundler/WebPack.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ describe('WebPack', () => {
1818
webpack(
1919
{
2020
entry: {
21-
app: './src/app.mjs'
21+
app: {
22+
import: './src/app.mjs',
23+
// see https://github.com/CoderLine/alphaTab/issues/2299
24+
library: {
25+
type: 'assign',
26+
name: 'alphaTabApp'
27+
}
28+
}
2229
},
2330
output: {
2431
filename: '[name]-[contenthash:8].js',
@@ -99,16 +106,26 @@ describe('WebPack', () => {
99106
expect(text).to.include('/* worklet bootstrap */ async function(__webpack_worklet__) {');
100107
// without custom bundling the app will bundle alphatab directly
101108
expect(text).to.include('class AlphaTabApiBase');
109+
// ensure the library mode is active as needed
110+
expect(text).to.include('alphaTabApp = __webpack_exports__');
102111

103112
appValidated = true;
104113
} else if (file.name.endsWith('.js')) {
105114
if (text.includes('class AlphaTabApiBase')) {
115+
// ensure the library mode is does not affect chunks
116+
expect(text).to.not.include('alphaTabApp = __webpack_exports__');
106117
coreFileValidated = true; // found core file (imported by worker and worklet)
107118
} else if (text.includes('initializeAudioWorklet()')) {
119+
// ensure the library mode is does not affect chunks
120+
expect(text).to.not.include('alphaTabApp = __webpack_exports__');
121+
108122
// ensure chunk installer is there
109123
expect(text).to.include('webpack/runtime/alphaTab audio worker chunk loading');
110124
workletValidated = true;
111125
} else if (text.includes('initializeWorker()')) {
126+
// ensure the library mode is does not affect chunks
127+
expect(text).to.not.include('alphaTabApp = __webpack_exports__');
128+
112129
// ensure chunk loader is there
113130
expect(text).to.include('webpack/runtime/importScripts chunk loading');
114131
workerValidated = true;

0 commit comments

Comments
 (0)