【问题标题】:Using Grunt Compass task to produce production CSS code without debug info使用 Grunt Compass 任务生成没有调试信息的生产 CSS 代码
【发布时间】:2013-07-21 19:59:13
【问题描述】:

我正在使用 Yeoman RC1.1 生成我的项目并加载了 grunt-contrib-compass 以在我的项目中使用 Scss。

当我执行grunt build 时,生成的 CSS 被缩小但充满了调试 cmets。它看起来像这样:

@media -sass-debug-info{filename{font-family:file\:\/\/\/\/Users\/myname\/Sites\/project\/app\/components\/sass-bootstrap\/lib\/_reset\.scss}line{font-family...

整个事情都被大量-sass-debug-info 代码污染了。

在 Gruntfile.js 中,我设置了以下选项(以及一系列其他选项)来关闭 /dist/ css 文件的调试 cmets:

grunt.initConfig({
    compass: {
        dist: {
            options: {
                debugInfo: false
            }
        }
    }
}

我是否认为通过将debugInfo 设置为false 来关闭它应该可以解决问题?

【问题讨论】:

    标签: css sass compass-sass gruntjs yeoman


    【解决方案1】:

    Grunt compass 使用位于“.tmp”的缓存。您应该在运行 Grunt 构建任务时清理此文件夹,或者手动执行。

    【讨论】:

    • 为什么不加任何解释就投反对票?这项技术对我有用,只是想分享一下。
    【解决方案2】:

    我最近遇到了这个错误,问题是 compass/grunt 不会重新编译你的 css 文件,除非正在监视的文件之一发生变化。您不仅需要更新 debugInfo:false,还需要对 scss 文件进行更改,以使其重新编译您的 css 文件,而无需内联调试信息。

    【讨论】:

      【解决方案3】:

      您必须在 compass.server.options.debugInfo 将 debugInfo 的值从 true 更改为 false

      compass: {
        options: {
          sassDir: '<%= yeoman.app %>/styles',
          cssDir: '.tmp/styles',
          generatedImagesDir: '.tmp/images/generated',
          imagesDir: '<%= yeoman.app %>/images',
          javascriptsDir: '<%= yeoman.app %>/scripts',
          fontsDir: '<%= yeoman.app %>/styles/fonts',
          importPath: '<%= yeoman.app %>/bower_components',
          httpImagesPath: '/images',
          httpGeneratedImagesPath: '/images/generated',
          httpFontsPath: '/styles/fonts',
          relativeAssets: false,
          assetCacheBuster: false,
          raw: 'Sass::Script::Number.precision = 10\n'
        },
        dist: {
          options: {
            generatedImagesDir: '<%= yeoman.dist %>/images/generated'
          }
        },
        server: {
          options: {
            //set degbugInfo false to produce css code without sass debugInfo
            debugInfo: false
          }
        }
      },
      

      【讨论】:

        【解决方案4】:

        尝试输出样式压缩https://github.com/gruntjs/grunt-contrib-compass#debuginfo 和环境:生产

        【讨论】:

        • 我把debugInfo改成了outputStyle和environment,结果是一样的:(
        • 您是否有可能与设置冲突的config.rb?
        • 我想通了。这对我来说是一个可以预防的错误。出于某种原因,在 /styles/ 目录中,我有一个 .css 文件,其中包含所有这些调试 cmets。所以 grunt 抓取了该目录中的所有内容并将其压缩在一起。
        猜你喜欢
        • 2013-10-28
        • 2020-03-17
        • 2014-08-03
        • 1970-01-01
        • 2016-08-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多