Replies: 3 comments
-
|
At the moment you can't :'( The only way to do it is to precompile your SW script. It's a bit to complex to write it down in an issue. |
Beta Was this translation helpful? Give feedback.
-
|
Ouuhh :( but many thanks for the reply. Do you have any advice on which way to go (doc, tutorial)? Is it something in webpack? |
Beta Was this translation helpful? Give feedback.
-
|
you'll need to run a separate webpack/rollup/bundler command before you run gatsby build or run it during gatsby process. Easiest would be to use microbundle: You'll have to change your offline config to this: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Is it possible to import whatever node module package in my custom SW?
Relevant information
In
gatsby-config.jsi am using thegatsby-plugin-offlineto register mysrc/custom-sw.js. Insrc/custom-sw.jsi am trying to use my locally installed lodash because i want to share it with React part of appsrc/pages/index.js.This is not specific to lodash but it is good example to demonstrate the problem.
Problem
As you can guess the
src/custom-sw.jsthrowing 404 lodash not found...Question
Is it even possible to use same library across React and SW part of app?
File contents
gatsby-config.js:src/custom-sw.js:package.json:src/pages/index.js:Beta Was this translation helpful? Give feedback.
All reactions