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文件夹路径