-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Description
🐞 Bug report
Command (mark with an x
)
- [ ] new
- [x] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc
Is this a regression?
no
Description
Angular 8 support build web worker command, but when the app deploys to CDN with --deploy-url
, the web worker ts will also loaded from the CDN URL.
This will cause cross domain error
ERROR Error: Uncaught (in promise): SecurityError: Failed to construct 'Worker':
It makes that impossible to use web worker with @angular/cli
in the production environment
Angular CLI should support cross-domain web worker loader with options or by default
- add plugin to
worker-plugin
like the code below https://github.com/GoogleChromeLabs/worker-plugin#plugins
async () => {
const codeString = await fetch(originWorkerUrl).then(res => res.text());
const localWorkerUrl = window.URL.createObjectURL(new Blob([codeString], {
type: 'application/javascript'
}));
}
-
or replace
worker-plugin
withworker-loader
which support cross-origin-policy
https://github.com/webpack-contrib/worker-loader#cross-origin-policy
Line 13 in 277d4ab
const WorkerPlugin = require('worker-plugin'); -
or should give an option to deploy the web worker build out to the assets folder
🔬 Minimal Reproduction
https://angular.io/guide/web-worker
with ng build --prod --deploy-url
to any CDN url can easily reproduce this error
🔥 Exception or Error
ERROR Error: Uncaught (in promise): SecurityError: Failed to construct 'Worker': Script at 'http://assets.daily.xxx.net/xxx.worker.js' cannot be accessed from origin 'http://daily.abc.xxx.net'.
Error: Failed to construct 'Worker': Script at 'http://assets.daily.xxx.net/xxx.worker.js' cannot be accessed from origin 'http://daily.abc.xxx.net'.
🌍 Your Environment
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 8.0.4
Node: 12.4.0
OS: darwin x64
Angular: 8.0.2
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.800.4
@angular-devkit/build-angular 0.800.4
@angular-devkit/build-optimizer 0.800.4
@angular-devkit/build-webpack 0.800.4
@angular-devkit/core 8.0.4
@angular-devkit/schematics 8.0.4
@angular/cli 8.0.4
@ngtools/webpack 8.0.4
@schematics/angular 8.0.4
@schematics/update 0.800.4
rxjs 6.4.0
typescript 3.4.5
webpack 4.30.0