4

我正在使用 grunt-rev 和 grunt-usemin 进行缓存破坏。问题是 grunt rev 修改了我的图片名称:logo.png 到 45475_logo.png 但只有根文件(/index.php header.php footer.php)被修改以获得新的 url。我所有其他的 php 文件都链接了错误的 img。

这是我的 Gruntfile.js :

        module.exports = function(grunt) {

        var gruntConfig = {
            app: 'app',
            dist: 'dist'
        };

      // Project configuration.
      grunt.initConfig({
        grunt: gruntConfig,

     clean: {
          dist: {
            files: [{
              dot: true,
              src: [
                '.tmp',
                '<%= grunt.dist %>/*',
                '!<%= grunt.dist %>/.git*'
              ]
            }]
          },
          server: '.tmp'
        },  

        useminPrepare: {
            html: ['<%= grunt.app %>/**/*.php'],
            options: {
                dest: '<%= grunt.dist %>/'
            }
        },

       usemin: {
           html: ['<%= grunt.dist %>/**/*.php'],
           css: ['<%= grunt.dist %>/**/*.css'],
           options: {
               dirs: ['<%= grunt.dist %>']
           }
       },

         imagemin: {                         
            dynamic: {  
                options: {                       
                    optimizationLevel: 7,
                    pngquant: true             
                },
              files: [{
                expand: true,                                   // Enable dynamic expansion
                cwd: '<%= grunt.app %>/img/',                   // Src matches are relative to this path
                src: ['**/*.{png,jpg}'],                        // Actual patterns to match
                dest: '<%= grunt.dist %>/img'                   // Destination path prefix
              }]
            }
          },
        copy: {
          main: {
            files: [
              {expand: true, cwd: '<%= grunt.app %>/', src: ['**'], dest: '<%= grunt.dist %>/'} // makes all src relative to cwd
            ]
          },
          font: {
             expand: true, 
             cwd: '<%= grunt.app %>/css/fonts/font-awesome/font/', 
             src: ['**'], 
             dest: '<%= grunt.dist %>/font/'
          },
          htaccess: {
              src: '<%= grunt.app %>/.htaccess',
              dest: '<%= grunt.dist %>/.htaccess'
          }
        },
        htmlcompressor:{
          dist: {
            files: [{
              expand: true,
              cwd: '<%= grunt.dist %>',
              src: [ '**/*.php'],
              dest: '<%= grunt.dist %>'
            }]
          }
        },
      rev: {
        options: {
          encoding: 'utf8',
          algorithm: 'md5',
          length: 8
        },
        assets: {
          files: [{
            src: [
              '<%= grunt.dist %>/js/{,*/}*.js',
              '<%= grunt.dist %>/css/{,*/}*.css',     
              '<%= grunt.dist %>/library/{,*/}*.css',
              '<%= grunt.dist %>/library/{,*/}*.js',
              '<%= grunt.dist %>/img/**/*.{jpg,jpeg,gif,png}',
              '<%= grunt.dist %>/**/*.{eot,svg,ttf,woff}'
            ]
          }]
        }
       }


    });

      grunt.loadNpmTasks('grunt-contrib-concat');
      grunt.loadNpmTasks('grunt-contrib-uglify');
      grunt.loadNpmTasks('grunt-contrib-cssmin');
      grunt.loadNpmTasks('grunt-contrib-clean');
      grunt.loadNpmTasks('grunt-contrib-htmlmin');
      grunt.loadNpmTasks('grunt-contrib-imagemin');  
      grunt.loadNpmTasks('grunt-processhtml');
      grunt.loadNpmTasks('grunt-usemin');
      grunt.loadNpmTasks('grunt-contrib-copy');
      grunt.loadNpmTasks('grunt-htmlcompressor');
      grunt.loadNpmTasks('grunt-rev');


      grunt.registerTask('build', [
        'clean:dist',
        'copy:main',
        'imagemin',
        'useminPrepare',
        'concat',
        'cssmin',
        'uglify',
        'rev',
        'usemin',
        'htmlcompressor',
        'copy:font',
        'copy:htaccess',
        'clean:server'
        ]);

        grunt.registerTask('default', [
            'build'
        ]);

    };

我不知道问题的根源。

4

0 回答 0