Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE REQUEST] Import external dependencies in Service Worker #63

Open
simonihmig opened this issue Feb 21, 2017 · 5 comments
Open

Comments

@simonihmig
Copy link
Contributor

It seems you cannot import anything that is not local to the service-worker folder, and that is not an ES6 module. The config for rollup does not include any plugins to allow importing of CJS or AMD modules, and there is no way to change that config from the outside.

Use case: would want to use libs like localForage or in this case idb-keyval inside a service worker to queue requests while offline, as using IDB directly is a bit cumbersome and localStorage is not available. But for sure there will be other use cases as well.

@dadleyy
Copy link

dadleyy commented Apr 11, 2018

FWIW I was able to get this working by using the rollup-plugin-node-resolve package like this.

@CodingDive
Copy link

Is there any problem with @dadleyy approach? I used his exact code an am finally able to import external dependencies. Would be nice to get his changes into master.

@aliHafizji
Copy link

@marten-dockyard @eshtadc Is there a way to import libs like idb-keyval inside the service worker right now? Can you please take a look at @dadleyy's approach and if possible merge to master?

@eshtadc
Copy link
Contributor

eshtadc commented Dec 12, 2018

Looks valid and intriguing. Could you pull together a PR that can be tested in some various scenarios?

@miguelcobain
Copy link

As a workaround you can manually import your dependency file in ember-cli-build.js like

app.import('node_modules/some-dependency/dist/umd/index.js', {
  outputFile: 'workers/some-dependency.js'
});

and in your service worker file have

importScripts('./workers/some-dependency.js');

Not the best experience, but gets the job done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants