1. 程式人生 > >node-sass 生成sourcemap/監聽檔案

node-sass 生成sourcemap/監聽檔案

node-sass 生成sourcemap/監聽檔案

0.無關緊要的叨叨(可跳過)

遇到問題->>
不知道怎麼用node-sass生成sourcemap檔案,我本地的ruby環境下是可以直接生成的
這裡寫圖片描述
但是現在做的專案就是要求把之前用ruby編譯的saas檔案全部改成用node-sass的,然後我以為只要在生成的css檔案後加一個/*# sourceMappingURL=style.css.map */就好了,而且瀏覽器是可以看到定位到的.scss的(後來才發現是之前編譯的map檔案,難怪對不上號,點進去是空白0.0),網上找了好一會兒都沒找到相關的命令,全是webpack或者ruby
,然後看了node-sass --help

才解決,之前看help裡有--source-map,沒看到後面的內容有Emit source map (boolean, or path to output .map file),明明是很簡單的東西,繞了一圈才解決,看來以後有問題要先看help


  Wrapper around libsass

  Usage:
    node-sass [options] <input.scss>
    cat <input.scss> | node-sass [options] > output.css

  Example: Compile foobar.scss to foobar.css
    node-sass --output-style compressed foobar.scss > foobar.css
    cat foobar.scss | node-sass --output-style compressed > foobar.css

  Example: Watch the sass directory for changes, compile with sourcemaps to the css directory
    node-sass --watch --recursive --output css
      --source-map true
--source-map-contents sass
Options -w, --watch Watch a directory or file -r, --recursive Recursively watch directories or files -o, --output Output directory -x, --omit-source-map-url Omit source map URL comment from output -i, --indented-syntax Treat
data from stdin as sass code (versus scss)
-q, --quiet Suppress log output except on error -v, --version Prints version info --output-style CSS output style (nested | expanded | compact | compressed) --indent-type Indent type for output CSS (space | tab) --indent-width Indent width; number of spaces or tabs (maximum value: 10) --linefeed Linefeed style (cr | crlf | lf | lfcr) --source-comments Include debug info in output --source-map Emit source map (boolean, or path to output .map file) --source-map-contents Embed include contents in map --source-map-embed Embed sourceMappingUrl as data URI --source-map-root Base path, will be emitted in source-map as is --include-path Path to look for imported files --follow Follow symlinked directories --precision The amount of precision allowed in decimal numbers --error-bell Output a bell character on errors --importer Path to .js file containing custom importer --functions Path to .js file containing custom functions --help Print usage info

1.node-sass編譯時生成sourcemap

node-sass --source-map map檔案路徑 sass檔案路徑 css檔案路徑

2. 監聽整個資料夾 時生成sourcemap

node-sass --source-map map檔案路徑 --watch -r sass資料夾路徑 -o css資料夾路徑

3. 監聽單個檔案 時生成sourcemap

node-sass --source-map map檔案路徑 --watch sass資料夾路徑 css資料夾路徑

這裡寫圖片描述