Javascript grunt contrib copy-使用不同的资源路径将HTML文件从根目录复制到DIST文件夹

Javascript grunt contrib copy-使用不同的资源路径将HTML文件从根目录复制到DIST文件夹,javascript,gruntjs,grunt-contrib-uglify,grunt-contrib-concat,grunt-contrib-copy,Javascript,Gruntjs,Grunt Contrib Uglify,Grunt Contrib Concat,Grunt Contrib Copy,我正在尝试将HTML文件从根文件夹复制到DIST文件夹,HTML将被缩小。到目前为止,我已经做到了 现在,当HTML文件被复制到DIST文件夹时,我想在所有包含的CSS和脚本中更改包含路径 有可能吗。我在科技论坛上做了很多搜索,但在任何地方都找不到 下面是示例代码: 'use strict'; /** * Grunt Module */ module.exports = function(grunt) { grunt.initConfig({ pkg: grun

我正在尝试将HTML文件从根文件夹复制到DIST文件夹,HTML将被缩小。到目前为止,我已经做到了

现在,当HTML文件被复制到DIST文件夹时,我想在所有包含的CSS和脚本中更改包含路径

有可能吗。我在科技论坛上做了很多搜索,但在任何地方都找不到

下面是示例代码:

'use strict';

/**
 * Grunt Module
 */
module.exports = function(grunt) {
    grunt.initConfig({
          pkg: grunt.file.readJSON('package.json'),

          sass: {
        dist: {
          options: {
            style: 'expanded',
            compass: true,
            sourcemap: false
          },
          files: {
            'dist/css/<%= pkg.name %>.styles.css': ['sass/**/*.scss']
          }
        }
      },

      concat: {
        dist: {
          src: ['scripts/**/*.js'],
          dest: 'dist/js/<%= pkg.name %>.scripts.js'
        }
      },

      uglify: {
         dist: {
            options: {
               sourceMap: false,
               banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
            },
            files: {
               'dist/js/<%= pkg.name %>.scripts.min.js': ['dist/js/<%= pkg.name %>.scripts.js']
            }
         }
      },

      cssmin: {
        minify: {
          src: 'dist/css/<%= pkg.name %>.styles.css',
          dest: 'dist/css/<%= pkg.name %>.styles.min.css'
        }
      },

      htmlmin: {
        dist: {
          options: {
            removeComments: true,
            collapseWhitespace: true
          },
          files: {
            'dist/index.html': 'index.html'
          }
        }
      },

      copy: {
        main: {
          files: [{
            expand: true,
            cwd: '/',
            src: '**/*.html',
            dest: 'dist/',
            filter: 'isFile',
            rename: function (dest, src) {
              // Change the path name utilize underscores for folders
              return dest + src.replace(/\//g,'_');
            }
          }],
        }
      },

      clean: {
        dist: ['dist/']
      },

        watch: {
            sass: {
                files: '**/*.scss',
                tasks: ['sass']
            },
            copy:{
              files: '**/*.html',
                tasks: ['sass']
            }
        }
    });

    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-sass');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-htmlmin');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-contrib-watch');

    grunt.registerTask('default',['clean', 'sass', 'concat', 'uglify', 'cssmin', 'htmlmin', 'watch']);
};
“严格使用”;
/**
*咕噜模块
*/
module.exports=函数(grunt){
grunt.initConfig({
pkg:grunt.file.readJSON('package.json'),
sass:{
地区:{
选项:{
样式:“扩展”,
罗盘:没错,
sourcemap:false
},
档案:{
'dist/css/.styles.css':['sass/***.scss']
}
}
},
康卡特:{
地区:{
src:['scripts/***/*.js'],
dest:'dist/js/.scripts.js'
}
},
丑陋的:{
地区:{
选项:{
sourceMap:false,
横幅:'/*!*/\n'
},
档案:{
'dist/js/.scripts.min.js':['dist/js/.scripts.js']
}
}
},
cssmin:{
缩小:{
src:'dist/css/.styles.css',
dest:'dist/css/.styles.min.css'
}
},
htmlmin:{
地区:{
选项:{
removeComments:对,
collapseWhitespace:true
},
档案:{
'dist/index.html':'index.html'
}
}
},
副本:{
主要内容:{
档案:[{
是的,
cwd:“/”,
src:“***.html”,
dest:'dist/',
筛选器:“isFile”,
重命名:函数(dest,src){
//更改文件夹的路径名并使用下划线
返回dest+src.replace(//\//g,“\”);
}
}],
}
},
清洁:{
地区:['dist/']
},
观察:{
sass:{
文件:'***.scss',
任务:['sass']
},
副本:{
文件:“***.html”,
任务:['sass']
}
}
});
grunt.loadNpmTasks(“grunt-contrib-clean”);
grunt.loadNpmTasks(“grunt-contrib-sass”);
grunt.loadNpmTasks(“grunt-contrib-concat”);
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks(“grunt-contrib-uglify”);
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks(“grunt-contrib-watch”);
registerTask('default',['clean','sass','concat','uglify','cssmin','htmlmin','watch']);
};
我不确定我做错了什么。谁能解释一下吗


提前感谢。

cwd:“/”
看起来不太对。文件系统根目录?你确定吗?我也尝试过为
cwd
放置SRC,但没有成功。我需要在
watch:{}
下添加所有任务?这是我想要替换复制的HTML文件中从根目录到DIST文件夹的路径的唯一解决方案!