dev@38: /** dev@38: * Created by lucas on 01/12/2016. dev@38: */ dev@38: dev@38: /* This is a really ad-hoc and crappy way of re-exporting modules, dev@38: * whilst trying to reduce global namespace pollution dev@38: * The main use case is providing access to npm modules inside a worker via importScripts dev@38: * over using some compiled version (a la *.min.js, *.umd.js etc) dev@38: * a better solution would be a custom webpack bundle, dev@38: * but the current build system in angular-cli doesn't provide a way for custom webpack bundles dev@38: * ....unless I am missing something dev@38: * dev@38: * this does, however, mean that modules will be loaded twice.. dev@38: * once by index.html and once by the worker.. dev@38: * one could potentially run a custom post build script dev@38: * to remove the script tag in index.html generated by angular-cli for scripts.bundle dev@38: * .. or find another way of doing this entirely.... dev@38: */ dev@38: dev@38: import extractionWorker from './app/services/feature-extraction/FeatureExtractionWorker'; dev@38: dev@38: const modules = { dev@38: 'feature-extraction-worker': extractionWorker, dev@38: }; dev@38: dev@38: if (typeof (self as any).importScripts === 'function' /* in a worker */) { dev@38: dev@38: self['require'] = (moduleName) => { dev@38: if (modules.hasOwnProperty(moduleName)) dev@38: return modules[moduleName]; dev@38: else dev@38: throw new Error(`Cannot find module '${moduleName}'`); dev@38: }; dev@38: }