gruntjscache-manifest

Using grunt-manifest to generate appcache manifests with relevant paths based on the root


I have a number of backbone apps all hosted on the same site. I am attempting to use grunt-manifest to generate appcache manifests for them. It generates the manifest file, but the links are wrong. I want each app to have a separate manifest file.

For example say I have an app called 'hello', it would be accessed via this url:

mydomain.com/apps/hello

so the main js and css files would be at:

mydomain.com/apps/hello/app.js

mydomain.com/apps/hello/style.css

etc.

There are also some shared components, found at say:

mydomain.com/shared/shared.js

(I dynamically load these with require.js so don't want to concat into the main app.js)

I specify the manifest in grunt like this:

manifest: {
    generate: {
        options: {
            basePath: '<%= gconf.dist_dir %>/',
            timestamp: true,
            network: ['*'],
        },

        files: [
            { 
                cwd: 'public/',
                src: [
                'apps/hello/*',
                'shared/*',
                // etc
                ],
            dest: '<%= gconf.dist_dir %>/public/apps/hello/manifest.appcache' },
        ]
    }
},

I believe the issue is I am trying to get grunt-manifest to generate an appcache manifest for a portion of a site not the root site. The manifest i get looks like this:

CACHE

apps/hello/app.js
apps/hello/style.css
shared/shared.js

When I load the page - the manifest retrieval fails because it is trying to access links like this:

mydomain.com/apps/hello/apps/hello/app.js

If I manually edit the manifest files and add a '/' in front of everything so it looks like this:

CACHE

/apps/hello/app.js
/apps/hello/style.css
/shared/shared.js

...then it all works.

The issue obviously being the manifest creating relative links, when I want them from the root.

I cannot for the life of me figure out how to get grunt-manifest to create these for me with a '/' in front.

I've tried experimenting with 'basePath' on its own, 'cwd' on its own, a combination of the two. If I leave the '/' off the end of say basePath or cwd and try adding it in the 'src' it doesn't work and I get an empty CACHE section.

I'm sure there must be an easy way of doing this with the grunt globing patterns, but I just can't work it out.

Any ideas?

(also - not enough rep to create a new tag, but a 'grunt-manifest' tag might be useful for others in the future)


Solution

  • I just ecnountered the same issue.

    I've forked the module here: https://github.com/killfish/grunt-manifest

    If you pass in the option absolutePath : true, it will prepend a '/'

    options: {
      **absolutePath: true,**
      network: ['http://*', 'https://*'],
      preferOnline: true,
      verbose: true,
      timestamp: true
    },