Git Product home page Git Product logo

grunt-service-worker's Introduction

grunt-service-worker

Greenkeeper badge

NPM version Build Status dependencies Status devDependencies Status

sw-precache wrapper

Getting Started

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-service-worker --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-service-worker');

The "service_worker" task

Overview

In your project's Gruntfile, add a section named service_worker to the data object passed into grunt.initConfig().

grunt.initConfig({
  service_worker: {
    options: {
      // Task-specific options go here.
    }
  },
});

Options

Options are passed to sw-precache. In addition this task defines some extra options:

options.baseDir

Type: String Default value: './'

The base working directory swPrecache scans.

options.workerFile

Type: String Default value: 'service-worker.js'

Service Worker entry filename, sw.js would be a good alternative.

Usage Examples

Default Options

In this example, service_worker will scans all files under public directory and generate service-worker.js with default options.

grunt.initConfig({
  service_worker: {
    options: {
      baseDir: 'public'
    }
  },
});

Custom Options

In this example, service_worker will scans all files under dist directory and generate sw.js with a custom staticFileGlobs.

grunt.initConfig({
  service_worker: {
    options: {
      baseDir: 'dist',
      workerFile: 'sw.js'
      staticFileGlobs: [
        '**/*.{gif,jpg,png}'
      ]
    }
  },
});

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

License

MIT

grunt-service-worker's People

Contributors

greenkeeper[bot] avatar renovate-bot avatar renovate[bot] avatar sparanoid avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

kublaj

grunt-service-worker's Issues

An in-range update of grunt-contrib-nodeunit is breaking the build 🚨

The devDependency grunt-contrib-nodeunit was updated from 2.0.0 to 2.1.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

grunt-contrib-nodeunit is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 3 commits.

  • d370717 v2.1.0
  • 02089d5 Clean up and update to latest contrib (#58)
  • deca505 Upgrade nodeunit-x from 0.12.1 to 0.13.0 and tap from ^12.0.1 to ^14.10.6 (#57)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Total precache size is about 0 B for 0 resources Ask Question

With grunt-sw-precache, I am trying to cache my application:

'develop': {
        navigateFallback: 'index.html',
        staticFileGlobs: [ '**/*.{js}'],
        stripPrefix: 'app',
        baseDir:'app',
        runtimeCaching: [{
          handler: 'networkFirst'
        }]
      },
    },

I tried different patterns. Always the same result

`My directory structure looks like this: projectRoot
______app
__________images
__________styles
__________controllers
__________jsFilesHere
___________app.js
_____________config.js
_____________index.html
_____________sw.js

I need to cache all my files to enable the application to run offline as well. For that matter I need to cache my entire app folderHow do I change thisstaticFileGlobs: ['index.html','/app/**/.{js,html,css,png,jpg,gif}'],to be able to get this working?I tried replacing it with:staticFileGlobs: ['.*'] as well. but yet I get the same message.`

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

npm
package.json
  • sw-precache ^5.2.1
  • grunt ^1.0.3
  • grunt-bump ^0.8.0
  • grunt-contrib-clean ^2.0.0
  • grunt-contrib-jshint ^2.0.0
  • grunt-contrib-nodeunit ^2.0.0
  • grunt-conventional-changelog ^6.1.0
  • grunt-npm 0.0.2
  • matchdep ^2.0.0
  • grunt >=0.4.0
  • node >= 0.8.0
travis
.travis.yml
  • node 10

  • Check this box to trigger a request for Renovate to run again on this repository

Multiple base directories

I'm getting around this, but it would be great to have that support.

module.exports = {
  options: {
    workerFile: 'sw.js'
  },
  build: {
    options: {
      baseDir: './dist'
    }
  },
  dev: {
    options: {
      baseDir: ['./public', './tmp'], // multiple directories :)
      workerDir: './tmp'
    }
  }
};

Does it make sense to support more than one directory?

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.