Giter Site home page Giter Site logo

Comments (6)

101arrowz avatar 101arrowz commented on September 24, 2024

There is no configuration. Parcel 2 makes it possible to, with 100% certainty, know which files are service workers. The manifest injects into every service worker found. Does that help @adrian2x?

from precache-manifest.

adrian2x avatar adrian2x commented on September 24, 2024

So the Parcel 2 docs are not clear on how to setup a service worker build. I think it needs to be setup as a target with context set to service-worker but I am not sure, I can't find a guide/recipe or specific instructions for service worker.
When I started looking for guides I stumbled upon your projects and it looks like they could help me with:

  • Generating a manifest with links to the dynamically built (hashed) assets
  • Preaching said dynamic assets

What I tried:
Installing this plugin & rebuilding

This did not modify my manifest or generate any precaching config, so I am not sure I'm using it right.
It would be great to see a self contained example of this plugin integrated with Parcel, or at least more info in the README about how to add this to an existing setup and what to expect.

from precache-manifest.

101arrowz avatar 101arrowz commented on September 24, 2024

It's actually quite simple to use service workers in Parcel 2. Parcel has always been good with zero config, and similarly here, you don't need any config to make service workers function.

package.json:

{
    "devDependencies": {
        "parcel": "^2.0.0-nightly.xxx",
        "parcel-config-precache-manifest": "^0.0.2"
    },
    "scripts": {
        "build": "parcel build public/index.html"
    }
}

.parcelrc:

{
    "extends": ["@parcel/config-default", "parcel-config-precache-manifest"]
}

public/index.html:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
  <script src="../src/index.js"></script>
</body>
</html>

src/index.js:

if ('serviceWorker' in navigator) {
  // This is the key line: Parcel auto-detects this is a service worker
  navigator.serviceWorker.register('sw.js');
}

src/sw.js:

// Everything should work here
console.log(self.__precacheManifest);
// do whatever you need to do in your service worker here
self.addEventListener('install', event => {

});

npm build should give you a working service worker with an injected manifest. Let me know if you need anything else. @adrian2x

from precache-manifest.

101arrowz avatar 101arrowz commented on September 24, 2024

@adrian2x Did that work for you?

from precache-manifest.

kkirby avatar kkirby commented on September 24, 2024

Here's the relevant documentation on Parcel's website: https://parceljs.org/languages/javascript/#service-workers

from precache-manifest.

101arrowz avatar 101arrowz commented on September 24, 2024

Yeah with @parcel/service-worker this package is obsolete.

from precache-manifest.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.