【问题标题】:How to make one css for each html?如何为每个 html 制作一个 css?
【发布时间】:2015-02-19 10:20:12
【问题描述】:

我正在使用 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']);


}

这个输出是:

运行“uncss:dist”(uncss)任务

ReferenceError:找不到变量:需要

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 创建的文件 1.css:101.86 kB → 14.62 kB

完成,没有错误。

基本上它只对数组中的第一个文件(obj[0]) 有效,对其他文件无效。

但是,如果我将obj[0]obj[1] 硬编码,那么两者都可以正常工作。但我需要一次性完成,因为我需要对超过 350 个文件执行此任务。有什么建议吗?

【问题讨论】:

    标签: javascript arrays node.js object gruntjs


    【解决方案1】:

    好的,因为自动任务在 grunt for uncss 中不起作用,我决定编写一个脚本,它需要一个 src 和一个 dest,并且每次都替换 grunt 文件中的行并运行它。

    【讨论】:

      猜你喜欢
      • 2011-05-07
      • 2022-01-24
      • 2015-08-13
      • 2013-10-18
      • 2019-08-14
      • 2017-08-18
      • 2020-09-05
      • 1970-01-01
      • 2019-09-15
      相关资源
      最近更新 更多