【问题标题】:SASS: How to remove /*# sourceMappingURL CommentSASS:如何删除 /*# sourceMappingURL 注释
【发布时间】:2023-03-12 20:07:01
【问题描述】:

我正在从 Windows 命令行启动 SASS watch。和 FireFox 开发者工具栏(带有 Show Sources)来查看 .scss 文件。

一切正常,但我意识到我的最终 .css 输出文件添加了一个额外的最后一行,例如:

/*# sourceMappingURL=index.css.map */

在我的公司中,我不允许留下此评论,我想知道我是否必须每次都手动删除它,或者有什么方法可以在我停止 SASS Watch 时自动删除它。

除了手动删除该行之外,问题是我正在使用 Git 进行版本控制,因此只需启动 SASS (--sass watch...) 将使我的 .css 文件显示为修改人GIT 作为额外的行被添加(因此它显示在要提交的文件中)

【问题讨论】:

    标签: css sass comments


    【解决方案1】:

    您看到的是sourcemap,它将编译后的 CSS 中的 CSS 类映射到各个 SASS 文件。截至SASS 3.4sourcemaps are enabled by default。要禁用它们,请使用--sourcemap=none,该行将不再添加,也不会生成源映射。

    您的命令将如下所示:

    sass --watch --sourcemap=none path/to/sass:path/to/css
    

    【讨论】:

    • 您好,我了解这一行的功能:)。我的问题是,当我停止 SASS 时是否会删除这条额外的行,以便 .css 文件在我的 GIT 版本控制中不会显示为“已修改”。
    • @user799138 停止执行 --watch 后无法自动删除源映射,之后您必须在没有源映射的情况下重新编译它。您可以编写脚本或使用任务运行器为您执行此操作。
    【解决方案2】:

    current Sass:

    sass --no-source-map ...
    

    用法

    $ sass --version && sass --help
    1.44.0
    Compile Sass to CSS.
    
    Usage: sass <input.scss> [output.css]
           sass <input.scss>:<output.css> <input/>:<output/> <dir/>
    
    === Input and Output ===================
        --[no-]stdin               Read the stylesheet from stdin.
        --[no-]indented            Use the indented syntax for input from stdin.
    -I, --load-path=<PATH>         A path to use when resolving imports.
                                   May be passed multiple times.
    -s, --style=<NAME>             Output style.
                                   [expanded (default), compressed]
        --[no-]charset             Emit a @charset or BOM for CSS with non-ASCII characters.
                                   (defaults to on)
        --[no-]error-css           When an error occurs, emit a stylesheet describing it.
                                   Defaults to true when compiling to a file.
        --update                   Only compile out-of-date stylesheets.
    
    === Source Maps ========================
        --[no-]source-map          Whether to generate source maps.
                                   (defaults to on)
        --source-map-urls          How to link from source maps to source files.
                                   [relative (default), absolute]
        --[no-]embed-sources       Embed source file contents in source maps.
        --[no-]embed-source-map    Embed source map contents in CSS.
    
    === Other ==============================
    -w, --watch                    Watch stylesheets and recompile when they change.
        --[no-]poll                Manually check for changes rather than using a native watcher.
                                   Only valid with --watch.
        --[no-]stop-on-error       Don't compile more files once an error is encountered.
    -i, --interactive              Run an interactive SassScript shell.
    -c, --[no-]color               Whether to use terminal colors for messages.
        --[no-]unicode             Whether to use Unicode characters for messages.
    -q, --[no-]quiet               Don't print warnings.
        --[no-]quiet-deps          Don't print compiler warnings from dependencies.
                                   Stylesheets imported through load paths count as dependencies.
        --[no-]verbose             Print all deprecation warnings even when they're repetitive.
        --[no-]trace               Print full Dart stack traces for exceptions.
    -h, --help                     Print this usage information.
        --version                  Print the version of Dart Sass.
    

    (在(例如)sass-maven-plugin(及其forks)):

    -DomitSourceMapingUrl=true
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-22
      • 2016-04-24
      • 1970-01-01
      • 1970-01-01
      • 2011-07-23
      • 2016-07-25
      相关资源
      最近更新 更多