Is your proposal related to a problem?
At present I can't seem to see a clean way to use imports inside the src folder and then have those scripts available to importScripts inside a serviceWorker
The use case I'm up against is sharing an idb store where in src it's easy enough to import the idb library and create an object to initialise and look up store items.
When it then comes to using that with a service worker via importScripts I can't seem to think of a neat way to copy across the idb library code etc short of a post build event but that would then require pulling the src file out of the node_modules folder.
EG
importScripts('/scripts/idb.js'); importScripts('/scripts/idb-store.js');
idb-store.js - Located in src
`import { openDB } from 'idb';
const idbStore = {
db: null,
init: function () {
if (idbStore.db) { return Promise.resolve(idbStore.db); }
return openDB('messages', 1, {
upgrade(db) {
db.createObjectStore('pizzaOrders', { autoIncrement: true, keyPath: 'id' });
}
}).then(function (db) {
return idbStore.db = db;
});
},
pizzaOrders: function (mode) {
return idbStore.init().then(function (db) {
return db.transaction('pizzaOrders', 'readwrite');
})
}
}
export default idbStore;`
I then have to clone that and alter it slightly for use in public/scripts so my service worker can access it:
`var idbStore = {
db: null,
init: function () {
if (idbStore.db) { return Promise.resolve(idbStore.db); }
return openDB('messages', 1, {
upgrade(db) {
db.createObjectStore('pizzaOrders', { autoIncrement: true, keyPath: 'id' });
}
}).then(function (db) {
return idbStore.db = db;
});
},
pizzaOrders: function (mode) {
return idbStore.init().then(function (db) {
return db.transaction('pizzaOrders', 'readwrite');
})
}
}`
The main problem is more so the node module idb I'm then using as I have to make a copy of it to put in the public/scripts/ folder so the service worker can use it.
Is there presently a better way?
Is your proposal related to a problem?
At present I can't seem to see a clean way to use imports inside the src folder and then have those scripts available to importScripts inside a serviceWorker
The use case I'm up against is sharing an idb store where in src it's easy enough to import the idb library and create an object to initialise and look up store items.
When it then comes to using that with a service worker via importScripts I can't seem to think of a neat way to copy across the idb library code etc short of a post build event but that would then require pulling the src file out of the node_modules folder.
EG
importScripts('/scripts/idb.js'); importScripts('/scripts/idb-store.js');idb-store.js - Located in src
`import { openDB } from 'idb';
const idbStore = {
db: null,
}
export default idbStore;`
I then have to clone that and alter it slightly for use in public/scripts so my service worker can access it:
`var idbStore = {
db: null,
}`
The main problem is more so the node module idb I'm then using as I have to make a copy of it to put in the public/scripts/ folder so the service worker can use it.
Is there presently a better way?