如何为每个html制作一个css?

How to make one css for each html?

我正在使用 grunt-uncss 连接所有使用的 css 规则并为每个 html 创建一个 css 文件。这是我目前的 Gruntfile.js:

'use strict';

module.exports = function(grunt) {

/*
  var src1=new Array("./4dlife/tools/experiments/index.html","./4dlife/tools/experiments/tests/test_resources_provider.html");

  var dest1=new Array("1.css","2.css");
*/
  var i=0;
  var obj = [{'1.css':'./4dlife/tools/experiments/index.html'}, {'2.css':'./4dlife/tools/experiments/tests/test_resources_provider.html'}];


  grunt.initConfig({

   // Remove unused CSS across multiple files, compressing the final output
    uncss: {
    dist: {
      files: obj
    },
      options: {
        compress:true
      }
    }

  });

  // Load the plugins
  grunt.loadNpmTasks('grunt-uncss');
  // Default tasks.
  grunt.registerTask('default', ['uncss']);


}

这个输出是:

Running "uncss:dist" (uncss) task

ReferenceError: Can't find variable:require

file:///home/pc009/code/4dlife_repo/4dlife/tools/experiments/tests/test_resources_provider.html:35

ReferenceError:找不到变量:要求

file:///home/pc009/code/4dlife_repo/4dlife/tools/experiments/index.html:35 File 1.css created: 101.86 kB → 14.62 kB

完成,没有错误。

基本上它仅适用于数组中的第一个文件 (obj[0]) 和其他文件的 none。

但是,如果我将 obj[0]obj[1] 硬编码,那么它可以很好地用于 both.But 我需要一次性完成,因为我需要在超过 350 个文件。有什么建议吗?

好吧,因为自动化任务在 g运行t 中对 uncss 不起作用,我决定编写一个脚本,它需要一个 src 和一个 dest,并替换 g[=12= 中的行]t 文件每次 运行 它。