Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): do not resolve web-workers in ser…
Browse files Browse the repository at this point in the history
…ver builds

Web-workers are not supported on the server and therefore we should not try include them in server builds.

Closes #20877
  • Loading branch information
alan-agius4 authored and filipesilva committed May 31, 2021
1 parent 2f29596 commit 77f81dc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/angular_devkit/build_angular/src/server/base_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,31 @@ describe('Server Builder', () => {

await run.stop();
});

it('should not try to resolve web-worker', async () => {
host.writeMultipleFiles({
'src/app/app.worker.ts': `
/// <reference lib="webworker" />
const foo: string = 'hello world';
addEventListener('message', ({ data }) => {
postMessage(foo);
});
`,
'src/main.server.ts': `
if (typeof Worker !== 'undefined') {
const worker = new Worker(new URL('./app/app.worker', import.meta.url), { type: 'module' });
worker.onmessage = ({ data }) => {
console.log('page got message:', data);
};
worker.postMessage('hello');
}
`,
});

const run = await architect.scheduleTarget(target);
const output = (await run.result) as ServerBuilderOutput;
expect(output.success).toBe(true);
await run.stop();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ export function getServerConfig(wco: WebpackConfigOptions): Configuration {
output: {
libraryTarget: 'commonjs',
},
module: {
parser: {
javascript: {
worker: false,
url: false,
},
},
},
plugins: [
// Fixes Critical dependency: the request of a dependency is an expression
new ContextReplacementPlugin(/@?hapi(\\|\/)/),
Expand Down

0 comments on commit 77f81dc

Please sign in to comment.