Backbone.js 对多个js文件使用grunt进行缓存破坏

Backbone.js 对多个js文件使用grunt进行缓存破坏,backbone.js,requirejs,gruntjs,Backbone.js,Requirejs,Gruntjs,关于grunt/Cachebasting有几个问题,但我没有找到足够接近我所寻找的东西。因此,一个新的问题 这就是我要找的。我的主干网/木偶应用程序的JS文件被组织到模块级文件夹中 |-应用程序 |- modules |- module1 |- scripts |- models |- views |- templates |- module2 |- scripts |- models

关于grunt/Cachebasting有几个问题,但我没有找到足够接近我所寻找的东西。因此,一个新的问题

这就是我要找的。我的主干网/木偶应用程序的JS文件被组织到模块级文件夹中

|-应用程序

|- modules
   |- module1
     |- scripts
        |- models
        |- views
        |- templates
   |- module2
     |- scripts
        |- models
        |- views
        |- templates
|- index.html
|- scripts
    |- app.js
|- styles
我需要的是一种方法,将所有module1连接到它自己的单个文件中(比如module1.min.js)。然后应该对该文件进行版本控制,并相应地更新其他JS文件(在其他模块中)中对模块1的引用。这样,只有在从客户端调用相应的功能时,我才能将模块下载到客户端,同时仍然可以获得缓存和缓存破坏的好处。如果我要将整个应用程序的所有js文件连接到一个文件中,这有助于避免代价高昂的下载

有什么解决办法吗

我确实喜欢开发人员JBCP在这个帖子中给出的答案-

然而,它涉及到调整requirejs库本身,我的客户不太愿意这样做(出于明显的原因)

我使用grunt进行构建,因此,我研究了grunt任务-concat、usemin、rev。我在应用程序中使用requireJS。但是我找不到一个解决方案来更新来自其他模块的js文件中对模块1的引用,我被卡住了。正在寻找此问题的解决方案,或者寻找构建模块级min.js文件以及缓存破坏的替代方法

非常感谢您的帮助

谢谢, DJ要连接,请使用“grunt contrib concat”

要缩小和丑化JavaScript文件,请使用“grunt contrib uglify”

缓存半身像:

1) 使用“grunt cache busting”-它使用文件的md5散列重命名html中的文件和引用

2) 如果要将自定义字符串附加到文件名

您可以使用“grunt text replace”或“grunt cache breaker”重命名html文件中的引用

您可以使用“grunt contrib copy”重命名文件名

例:-

要删除原始文件,请使用“grunt contrib clean”。您可能需要为此使用另一个“复制”任务

供参考:我的默认任务。 registerTask('default'、['clean'、'copy:dist'、'replace'、'copy:rename'、'clean:old'、'copy:after'、'clean:after'])

module.exports = function (grunt) {
    var timeStamp;

    // Project configuration.
    grunt.initConfig({
copy: {            
            rename: {
                files: [
                    {
                        expand: true,
                        dot: true,
                        cwd: 'js/',
                        dest: 'dist/js/',
                        src: [
                            '*.*'
                        ],
                        rename: function (dest, src) {
                            return dest + src.replace('.js','.' + timeStamp + '.js');
                        }
                    }
                ]
            }
},
replace: {

            bust: {
                src: ['dist/*.html'],
                overwrite: true,                 // overwrite matched source files
                replacements: [
                    {
                        from: '.js',

                        to: function () {
                            timeStamp = new Date().getTime() ;
                            return '.' + timeStamp + '.js';
                        }
                    }
                ]
            }
        }
});
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-text-replace');