Gruntjs 使用grunt清单根据根目录生成具有相关路径的appcache清单

Gruntjs 使用grunt清单根据根目录生成具有相关路径的appcache清单,gruntjs,cache-manifest,Gruntjs,Cache Manifest,我有许多主干应用程序都托管在同一个站点上。我正在尝试使用grunt清单为它们生成appcache清单。它生成清单文件,但链接错误。我希望每个应用程序都有一个单独的清单文件 例如,假设我有一个名为“hello”的应用程序,可以通过以下url访问: mydomain.com/apps/hello 因此,主要的js和css文件位于: mydomain.com/apps/hello/app.js mydomain.com/apps/hello/style.css 等等 还有一些共享组件,如:

我有许多主干应用程序都托管在同一个站点上。我正在尝试使用grunt清单为它们生成appcache清单。它生成清单文件,但链接错误。我希望每个应用程序都有一个单独的清单文件

例如,假设我有一个名为“hello”的应用程序,可以通过以下url访问:


mydomain.com/apps/hello

因此,主要的js和css文件位于:


mydomain.com/apps/hello/app.js


mydomain.com/apps/hello/style.css

等等

还有一些共享组件,如:


mydomain.com/shared/shared.js

(我用require.js动态加载它们,所以不想将其压缩到主app.js中)

我在grunt中指定清单如下:

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' },
        ]
    }
},
CACHE

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

/apps/hello/app.js
/apps/hello/style.css
/shared/shared.js
当我加载页面时,清单检索失败,因为它试图访问如下链接:

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' },
        ]
    }
},
CACHE

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

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

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

如果我手动编辑清单文件,并在所有内容前面添加一个“/”,则如下所示:

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' },
        ]
    }
},
CACHE

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

/apps/hello/app.js
/apps/hello/style.css
/shared/shared.js
…然后一切都会好起来

问题显然是清单创建了相对链接,而我希望它们来自根目录

我一辈子都想不出如何让grunt清单为我创建一个前面有“/”的清单

我尝试过单独使用“basePath”和“cwd”进行试验,这两种方法是两者的结合。如果我将“/”保留在basePath或cwd的末尾,并尝试将其添加到“src”中,它将不起作用,并且会得到一个空的缓存部分

我相信一定有一种简单的方法可以用咕噜咕噜的全球化模式来实现这一点,但我就是无法解决这个问题

有什么想法吗


(还有-没有足够的rep来创建一个新的标记,但是“grunt manifest”标记在将来可能对其他人有用)

我刚刚宣布了同样的问题

我在这里分叉了模块:

如果传入选项absolutePath:true,它将在“/”前面加上前缀

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

很好,很好。比我使用的“../../”解决方案要好得多。希望他们能把这些变化合并在一起。