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.
-
Summary
Is it possible to import whatever node module package in my custom SW?
Relevant information
In
gatsby-config.js
i am using thegatsby-plugin-offline
to register mysrc/custom-sw.js
. Insrc/custom-sw.js
i 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.js
throwing 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