@adamlui/scss-to-css 1.5.1 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +144 -44
- package/docs/LICENSE.md +21 -9
- package/docs/SECURITY.md +17 -5
- package/docs/zh-cn/LICENSE.md +21 -0
- package/docs/zh-cn/README.md +228 -0
- package/docs/zh-cn/SECURITY.md +17 -0
- package/docs/zh-tw/LICENSE.md +21 -0
- package/docs/zh-tw/README.md +227 -0
- package/docs/zh-tw/SECURITY.md +17 -0
- package/package.json +48 -48
- package/scss-to-css.js +208 -159
package/README.md
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
|
+
<div align="right">
|
|
2
|
+
<h6>
|
|
3
|
+
<picture>
|
|
4
|
+
<source type="image/svg+xml" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/white/icon32.svg">
|
|
5
|
+
<img height=14 src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/black/icon32.svg">
|
|
6
|
+
</picture>
|
|
7
|
+
English |
|
|
8
|
+
<a href="https://github.com/adamlui/js-utils/tree/main/scss-to-css/docs/zh-cn#readme">简体中文</a> |
|
|
9
|
+
<a href="https://github.com/adamlui/js-utils/tree/main/scss-to-css/docs/zh-tw#readme">繁體中文</a>
|
|
10
|
+
</h6>
|
|
11
|
+
</div>
|
|
12
|
+
|
|
1
13
|
# { } scss-to-css.js
|
|
2
14
|
|
|
3
15
|
### Recursively compile all SCSS files into minified CSS.
|
|
4
16
|
|
|
5
17
|
<a href="https://www.npmjs.com/package/@adamlui/scss-to-css"><img height=31 src="https://img.shields.io/npm/dt/%40adamlui%2Fscss-to-css?logo=npm&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
6
18
|
<a href="#%EF%B8%8F-mit-license"><img height=31 src="https://img.shields.io/badge/License-MIT-red.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
7
|
-
<a href="https://www.npmjs.com/package/@adamlui/scss-to-css?activeTab=versions"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.
|
|
19
|
+
<a href="https://www.npmjs.com/package/@adamlui/scss-to-css?activeTab=versions"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.6.0-fc7811.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
8
20
|
<a href="https://www.npmjs.com/package/@adamlui/scss-to-css?activeTab=code"><img height=31 src="https://img.shields.io/npm/unpacked-size/%40adamlui%2Fscss-to-css?style=for-the-badge&logo=ebox&logoColor=white&color=blue&labelColor=464646"></a>
|
|
9
21
|
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:scss-to-css/scss-to-css.js"><img height=31 src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fsonarcloud.io%2Fapi%2Fmeasures%2Fcomponent%3Fcomponent%3Dadamlui_js-utils%3Ascss-to-css%2Fscss-to-css.js%26metricKeys%3Dvulnerabilities&query=%24.component.measures.0.value&style=for-the-badge&logo=sonarcloud&logoColor=white&labelColor=464646&label=Vulnerabilities&color=gold"></a>
|
|
10
22
|
|
|
@@ -18,12 +30,19 @@ As a **global utility**:
|
|
|
18
30
|
npm install -g @adamlui/scss-to-css
|
|
19
31
|
```
|
|
20
32
|
|
|
21
|
-
As a **dev dependency
|
|
33
|
+
As a **dev dependency** (e.g. for build scripts):
|
|
22
34
|
|
|
23
35
|
```
|
|
24
36
|
npm install -D @adamlui/scss-to-css
|
|
25
37
|
```
|
|
26
38
|
|
|
39
|
+
|
|
40
|
+
As a **runtime dependency** (e.g. for on-the-fly compilation):
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
npm install @adamlui/scss-to-css
|
|
44
|
+
```
|
|
45
|
+
|
|
27
46
|
## 💻 Usage
|
|
28
47
|
|
|
29
48
|
The basic **global command** is:
|
|
@@ -32,13 +51,11 @@ The basic **global command** is:
|
|
|
32
51
|
scss-to-css
|
|
33
52
|
```
|
|
34
53
|
|
|
35
|
-
**💡 Note:** Pass `-n` or `--dry-run` to only see what files will be processed.
|
|
36
|
-
|
|
37
54
|
Sample output:
|
|
38
55
|
|
|
39
56
|
<img src="https://github.com/adamlui/js-utils/blob/main/scss-to-css/media/images/sample-output.png">
|
|
40
57
|
|
|
41
|
-
**💡 Note:** Source maps are also generated by default unless `-S` or `--
|
|
58
|
+
**💡 Note:** Source maps are also generated by default unless `-S` or `--no-source-maps` is passed.
|
|
42
59
|
|
|
43
60
|
#
|
|
44
61
|
|
|
@@ -48,10 +65,10 @@ To specify **input/output** paths:
|
|
|
48
65
|
scss-to-css [input_path] [output_path]
|
|
49
66
|
```
|
|
50
67
|
|
|
51
|
-
- `[input_path]`: Path to SCSS file or directory containing SCSS files to be compiled, relative to the current working directory.
|
|
52
|
-
- `[output_path]`: Path to file or directory where CSS +
|
|
68
|
+
- `[input_path]`: Path to SCSS file or directory containing SCSS files to be compiled, relative to the current working directory.
|
|
69
|
+
- `[output_path]`: Path to file or directory where CSS + source map files will be stored, relative to original file location (if not provided, `css/` is used).
|
|
53
70
|
|
|
54
|
-
**💡 Note:** If folders are passed, files will be processed recursively
|
|
71
|
+
**💡 Note:** If folders are passed, files will be processed recursively unless `-R` or `--no-recursion` is passed.
|
|
55
72
|
|
|
56
73
|
#
|
|
57
74
|
|
|
@@ -66,35 +83,130 @@ To use as a **package script**, in your project's `package.json`:
|
|
|
66
83
|
Replace `<scss-to-css-cmd>` with `scss-to-css` + optional args. Then, `npm run build:css` can be used to run the command.
|
|
67
84
|
<br><br>
|
|
68
85
|
|
|
69
|
-
|
|
86
|
+
### Example commands
|
|
70
87
|
|
|
71
|
-
|
|
88
|
+
Compile all SCSS files in the **current directory** (outputs to `css/`):
|
|
72
89
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
90
|
+
```
|
|
91
|
+
scss-to-css
|
|
92
|
+
```
|
|
76
93
|
|
|
77
|
-
|
|
94
|
+
Compile all SCSS files in a **specific directory** (outputs to `path/to/your/directory/css/`):
|
|
78
95
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
96
|
+
```
|
|
97
|
+
scss-to-css path/to/your/directory
|
|
98
|
+
```
|
|
82
99
|
|
|
83
|
-
|
|
100
|
+
Compile a **specific file** (outputs to `path/to/your/css/file.min.css`):
|
|
84
101
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
102
|
+
```
|
|
103
|
+
scss-to-css path/to/your/file.scss
|
|
104
|
+
```
|
|
88
105
|
|
|
89
|
-
|
|
106
|
+
Specify both **input and output** directories (outputs to `output_folder/`):
|
|
90
107
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
108
|
+
```
|
|
109
|
+
scss-to-css input_folder output_folder
|
|
110
|
+
```
|
|
94
111
|
|
|
95
112
|
**💡 Note:** Output CSS is minified unless `-M` or `--no-minify` is passed.
|
|
96
113
|
<br><br>
|
|
97
114
|
|
|
115
|
+
### Command line options
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
Config options:
|
|
119
|
+
-n, --dry-run Don't actually compile the file(s), just
|
|
120
|
+
show if they will be processed.
|
|
121
|
+
-d, --include-dotfolders Include dotfolders in file search.
|
|
122
|
+
-S, --no-source-maps Prevent source maps from being generated.
|
|
123
|
+
-M, --no-minify Disable minification of output CSS.
|
|
124
|
+
-R, --no-recursion Disable recursive file searching.
|
|
125
|
+
-q, --quiet Suppress all logging except errors.
|
|
126
|
+
|
|
127
|
+
Info commands:
|
|
128
|
+
-h, --help Display this help screen.
|
|
129
|
+
-v, --version Show version number.
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## 🔌 API reference
|
|
133
|
+
|
|
134
|
+
You can also import **scss-to-css** into your app to use its API methods, both as an ECMAScript module or a CommonJS module.
|
|
135
|
+
|
|
136
|
+
#### ESM:
|
|
137
|
+
|
|
138
|
+
```js
|
|
139
|
+
import * as scssToCSS from '@adamlui/scss-to-css';
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
#### CJS:
|
|
143
|
+
|
|
144
|
+
```js
|
|
145
|
+
const scssToCSS = require('@adamlui/scss-to-css');
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### compile(inputPath, options)
|
|
149
|
+
|
|
150
|
+
This function compiles SCSS found in the `inputPath` provided into CSS data.
|
|
151
|
+
|
|
152
|
+
If a **file path** is passed, the file's code is compiled to CSS, then an object containing `srcPath` + `code` + `error` is returned:
|
|
153
|
+
|
|
154
|
+
```js
|
|
155
|
+
const compileResult = scssToCSS.compile('assets/style.scss');
|
|
156
|
+
console.log(compileResult.error); // runtime error, or `undefined` if no error
|
|
157
|
+
console.log(compileResult.code); // compiled CSS output of assets/style.scss
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
If a **directory path** is passed, SCSS files are searched for (recursively by default), each one's code is loaded then compiled, then an array of objects containing `srcPath` + `code` + `error` is returned:
|
|
161
|
+
|
|
162
|
+
```js
|
|
163
|
+
const results = scssToCSS.compile('.');
|
|
164
|
+
results.forEach(result =>
|
|
165
|
+
console.log(result.srcPath) // paths to SCSS files in working directory + all nested directories
|
|
166
|
+
);
|
|
167
|
+
console.log(results[1].code); // compiled CSS output of 2nd SCSS file if found, or `undefined` if not found
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Options are boolean, passed as object properties. For example:
|
|
171
|
+
|
|
172
|
+
```js
|
|
173
|
+
scssToCSS.compile(inputDir, { minify: false });
|
|
174
|
+
// returns data objects where `.code` contains unminified CSS
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Possible parameters (and their default settings) are:
|
|
178
|
+
|
|
179
|
+
```
|
|
180
|
+
recursive (true) Recursively search for nested files if dir path
|
|
181
|
+
passed.
|
|
182
|
+
verbose (true) Show logging in console/terminal.
|
|
183
|
+
dotFolders (false) Include dotfolders in file search.
|
|
184
|
+
minify (true) Minify output CSS.
|
|
185
|
+
sourceMaps (true) Generate CSS source maps.
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### findSCSS(searchDir, options)
|
|
189
|
+
|
|
190
|
+
This function searches for all SCSS files within the `searchDir` string passed (useful for discovering what files [`compile()`](#compileinputpath-options) will process) and returns an array containing their filepaths.
|
|
191
|
+
|
|
192
|
+
Options are boolean, passed as object properties. For example:
|
|
193
|
+
|
|
194
|
+
```js
|
|
195
|
+
scssToCSS.findSCSS(searchDir, { recursive: false });
|
|
196
|
+
// returns array containing filepaths to SCSS files in exactly `searchDir`
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Possible parameters (and their default settings) are:
|
|
200
|
+
|
|
201
|
+
```
|
|
202
|
+
recursive (true) Recursively search for nested files if dir path
|
|
203
|
+
passed.
|
|
204
|
+
verbose (false) Show logging in console/terminal.
|
|
205
|
+
dotFolders (false) Include dotfolders in file search.
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
<br>
|
|
209
|
+
|
|
98
210
|
## 💖 Support
|
|
99
211
|
|
|
100
212
|
Please consider [giving a GitHub ⭐](https://github.com/adamlui/js-utils) if this helped you!
|
|
@@ -102,25 +214,13 @@ Please consider [giving a GitHub ⭐](https://github.com/adamlui/js-utils) if th
|
|
|
102
214
|
|
|
103
215
|
## 🏛️ MIT License
|
|
104
216
|
|
|
105
|
-
**Copyright
|
|
106
|
-
|
|
107
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
108
|
-
|
|
109
|
-
in
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
furnished to do so, subject to the following conditions:
|
|
113
|
-
|
|
114
|
-
The above copyright notice and this permission notice shall be included in all
|
|
115
|
-
copies or substantial portions of the Software.
|
|
116
|
-
|
|
117
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
118
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
119
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
120
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
121
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
122
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
123
|
-
SOFTWARE.
|
|
217
|
+
**Copyright © 2024 [Adam Lui](https://github.com/adamlui)**
|
|
218
|
+
|
|
219
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
220
|
+
|
|
221
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
222
|
+
|
|
223
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
124
224
|
|
|
125
225
|
<br>
|
|
126
226
|
|
package/docs/LICENSE.md
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
<div align="right">
|
|
2
|
+
<h6>
|
|
3
|
+
<picture>
|
|
4
|
+
<source type="image/svg+xml" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/white/icon32.svg">
|
|
5
|
+
<img height=14 src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/black/icon32.svg">
|
|
6
|
+
</picture>
|
|
7
|
+
English |
|
|
8
|
+
<a href="zh-cn/LICENSE.md">简体中文</a> |
|
|
9
|
+
<a href="zh-tw/LICENSE.md">繁體中文</a>
|
|
10
|
+
</h6>
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
# 🏛️ MIT License
|
|
14
|
+
|
|
15
|
+
**Copyright © 2024 [Adam Lui](https://github.com/adamlui)**
|
|
16
|
+
|
|
17
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
18
|
+
|
|
19
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/docs/SECURITY.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
<div align="right">
|
|
2
|
+
<h6>
|
|
3
|
+
<picture>
|
|
4
|
+
<source type="image/svg+xml" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/white/icon32.svg">
|
|
5
|
+
<img height=14 src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/black/icon32.svg">
|
|
6
|
+
</picture>
|
|
7
|
+
English |
|
|
8
|
+
<a href="zh-cn/SECURITY.md">简体中文</a> |
|
|
9
|
+
<a href="zh-tw/SECURITY.md">繁體中文</a>
|
|
10
|
+
</h6>
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
# 🛡️ Security Policy
|
|
14
|
+
|
|
15
|
+
If you find a vulnerability, please open a [draft security advisory](https://github.com/adamlui/js-utils/security/advisories/new).
|
|
16
|
+
|
|
17
|
+
Pull requests are also welcome, but for safety reasons, send an email to <adam@kudoai.com> and wait for a response before making it public.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<div align="right">
|
|
2
|
+
<h6>
|
|
3
|
+
<picture>
|
|
4
|
+
<source type="image/svg+xml" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/white/icon32.svg">
|
|
5
|
+
<img height=14 src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/black/icon32.svg">
|
|
6
|
+
</picture>
|
|
7
|
+
简体中文 |
|
|
8
|
+
<a href="../LICENSE.md">English</a> |
|
|
9
|
+
<a href="../zh-tw/LICENSE.md">繁體中文</a>
|
|
10
|
+
</h6>
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
# 🏛️ MIT 许可证
|
|
14
|
+
|
|
15
|
+
**版权所有 © 2023–2024 [刘展鹏 (Adam Lui)](https://github.com/adamlui)**
|
|
16
|
+
|
|
17
|
+
特此免费向任何获得副本的人授予许可本软件和相关文档文件(『软件』),处理在软件中不受限制,包括但不限于权利使用、复制、修改、合并、发布、分发、再许可和/或出售该软件的副本,并允许该软件是提供这样做,但须满足以下条件:
|
|
18
|
+
|
|
19
|
+
上述版权声明和本许可声明应包含在所有软件的副本或重要部分。
|
|
20
|
+
|
|
21
|
+
本软件『按原样』提供,不提供任何形式的明示或保证暗示的,包括但不限于适销性保证,适用于特定目的和非侵权。 在任何情况下都不得作者或版权持有人对任何索赔、损害或其他责任,无论是在合同、侵权或其他方面的行为中,由以下原因引起,出于或与软件或使用或其他交易有关软件。
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
<div align="right">
|
|
2
|
+
<h6>
|
|
3
|
+
<picture>
|
|
4
|
+
<source type="image/svg+xml" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/white/icon32.svg">
|
|
5
|
+
<img height=14 src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/black/icon32.svg">
|
|
6
|
+
</picture>
|
|
7
|
+
简体中文 |
|
|
8
|
+
<a href="../..#readme">English</a> |
|
|
9
|
+
<a href="../zh-tw#readme">繁體中文</a>
|
|
10
|
+
</h6>
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
# { } scss-to-css.js
|
|
14
|
+
|
|
15
|
+
### 将所有 SCSS 文件递归编译为缩小的 CSS。
|
|
16
|
+
|
|
17
|
+
<a href="https://www.npmjs.com/package/@adamlui/scss-to-css"><img height=31 src="https://img.shields.io/npm/dt/%40adamlui%2Fscss-to-css?label=%E4%B8%8B%E8%BD%BD&logo=npm&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
18
|
+
<a href="#%EF%B8%8F-mit-%E8%AE%B8%E5%8F%AF%E8%AF%81"><img height=31 src="https://img.shields.io/badge/许可证-MIT-red.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
19
|
+
<a href="https://www.npmjs.com/package/@adamlui/scss-to-css?activeTab=versions"><img height=31 src="https://img.shields.io/badge/最新版本-1.6.0-fc7811.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
20
|
+
<a href="https://www.npmjs.com/package/@adamlui/scss-to-css?activeTab=code"><img height=31 src="https://img.shields.io/npm/unpacked-size/%40adamlui%2Fscss-to-css?label=%E6%8B%86%E5%B0%81%E5%B0%BA%E5%AF%B8&style=for-the-badge&logo=ebox&logoColor=white&color=blue&labelColor=464646"></a>
|
|
21
|
+
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:scss-to-css/scss-to-css.js"><img height=31 src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fsonarcloud.io%2Fapi%2Fmeasures%2Fcomponent%3Fcomponent%3Dadamlui_js-utils%3Ascss-to-css%2Fscss-to-css.js%26metricKeys%3Dvulnerabilities&query=%24.component.measures.0.value&style=for-the-badge&logo=sonarcloud&logoColor=white&labelColor=464646&label=%E6%BC%8F%E6%B4%9E&color=gold"></a>
|
|
22
|
+
|
|
23
|
+
<img height=8px width="100%" src="https://github.com/adamlui/js-utils/blob/main/docs/images/aqua-separator.png">
|
|
24
|
+
|
|
25
|
+
## ⚡ 如何安装
|
|
26
|
+
|
|
27
|
+
作为**全局实用程序**:
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
npm install -g @adamlui/scss-to-css
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
作为**开发人员依赖**(例如,对于构建脚本):
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
npm install -D @adamlui/scss-to-css
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
作为**运行时依赖**(例如,用于动态编译):
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
npm install @adamlui/scss-to-css
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## 💻 命令行使用
|
|
47
|
+
|
|
48
|
+
基本的**全局命令**是:
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
scss-to-css
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
示例输出:
|
|
55
|
+
|
|
56
|
+
<img src="https://github.com/adamlui/js-utils/blob/main/scss-to-css/media/images/sample-output.png">
|
|
57
|
+
|
|
58
|
+
**💡 笔记:** 默认情况下也会生成源映射,除非传递 `-S` 或 `--no-source-maps`。
|
|
59
|
+
|
|
60
|
+
#
|
|
61
|
+
|
|
62
|
+
指定**输入/输出**路径:
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
scss-to-css [input_path] [output_path]
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
- `[input_path]`: SCSS 文件或包含要编译的 SCSS 文件的目录的路径,相对于当前工作目录。
|
|
69
|
+
- `[output_path]`: 将存储 CSS + 源映射文件的文件或目录的路径,相对于原始文件位置(如果未提供,则使用 `css/`)。
|
|
70
|
+
|
|
71
|
+
**💡 注意:** 如果传递文件夹,文件将被递归处理,除非传递 `-R` 或 `--no-recursion`。
|
|
72
|
+
|
|
73
|
+
#
|
|
74
|
+
|
|
75
|
+
要用作 **包脚本**,请在项目的 `package.json` 中:
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
"scripts": {
|
|
79
|
+
"build:css": "<scss-to-css-cmd>"
|
|
80
|
+
},
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
将 `<scss-to-css-cmd>` 替换为 `scss-to-css` + 可选参数。 然后,可以使用 `npm run build:css` 来运行该命令。
|
|
84
|
+
<br><br>
|
|
85
|
+
|
|
86
|
+
### 命令示例
|
|
87
|
+
|
|
88
|
+
编译 **当前目录** 中的所有 SCSS 文件(输出到 `css/`):
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
scss-to-css
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
编译 **特定目录** 中的所有 SCSS 文件(输出到 `path/to/your/directory/css/`):
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
scss-to-css path/to/your/directory
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
编译一个**特定文件**(输出到 `path/to/your/css/file.min.css`):
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
scss-to-css path/to/your/file.scss
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
指定 **输入和输出** 目录(输出到 `output_folder/`):
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
scss-to-css input_folder output_folder
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**💡 注意:** 除非传递 `-M` 或 `--no-minify` ,否则输出 CSS 会被缩小。
|
|
113
|
+
<br><br>
|
|
114
|
+
|
|
115
|
+
### 命令行选项
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
配置选项:
|
|
119
|
+
-n, --dry-run 实际上并不缩小文件,只是显示它们是否会被处理。
|
|
120
|
+
-d, --include-dotfolders 在文件搜索中包括点文件夹。
|
|
121
|
+
-S, --no-source-maps 防止生成源映射。
|
|
122
|
+
-M, --no-minify 禁用输出 CSS 的缩小。
|
|
123
|
+
-R, --no-recursion 禁用递归文件搜索。
|
|
124
|
+
-q, --quiet 禁止除错误之外的所有日志记录。
|
|
125
|
+
|
|
126
|
+
信息命令:
|
|
127
|
+
-h, --help 显示帮助屏幕。
|
|
128
|
+
-v, --version 显示版本号。
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## 🔌 API 参考
|
|
132
|
+
|
|
133
|
+
您还可以将 **scss-to-css** 导入您的应用程序以使用其 API 方法,无论是作为 ECMAScript 模块还是 CommonJS 模块。
|
|
134
|
+
|
|
135
|
+
#### ESM:
|
|
136
|
+
|
|
137
|
+
```js
|
|
138
|
+
import * as scssToCSS from '@adamlui/scss-to-css';
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
#### CJS:
|
|
142
|
+
|
|
143
|
+
```js
|
|
144
|
+
const scssToCSS = require('@adamlui/scss-to-css');
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### compile(inputPath, options)
|
|
148
|
+
|
|
149
|
+
此函数将在 `inputPath` 中找到的 SCSS 编译为 CSS 数据。
|
|
150
|
+
|
|
151
|
+
如果传递 **文件路径**,则文件的代码将编译为 CSS,然后返回一个包含 `srcPath` + `code` + `error` 的对象:
|
|
152
|
+
|
|
153
|
+
```js
|
|
154
|
+
const compileResult = scssToCSS.compile('assets/style.scss');
|
|
155
|
+
console.log(compileResult.error); // 运行时错误,如果没有错误则为 `undefined`
|
|
156
|
+
console.log(compileResult.code); // 编译后的 assets/style.scss CSS 输出
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
如果传递 **目录路径**,则搜索 SCSS 文件(默认情况下递归),加载每个文件的代码并编译,然后返回包含 `srcPath` + `code` + `error` 的对象数组:
|
|
160
|
+
|
|
161
|
+
```js
|
|
162
|
+
const results = scssToCSS.compile('.');
|
|
163
|
+
results.forEach(result =>
|
|
164
|
+
console.log(result.srcPath) // 工作目录 + 所有嵌套目录中 SCSS 文件的路径
|
|
165
|
+
);
|
|
166
|
+
console.log(results[1].code); // 如果找到,则编译第二个 SCSS 文件的 CSS 输出,如果未找到,则为 `undefined`
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
选项是布尔值,作为对象属性传递。 例如:
|
|
170
|
+
|
|
171
|
+
```js
|
|
172
|
+
scssToCSS.compile(inputDir, { minify: false });
|
|
173
|
+
// 返回 `.code` 包含未缩小 CSS 的数据对象
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
可能的参数(及其默认设置)有:
|
|
177
|
+
|
|
178
|
+
```
|
|
179
|
+
recursive (true) 如果传递目录路径,则递归搜索嵌套文件。
|
|
180
|
+
verbose (true) 在控制台/终端中显示日志记录。
|
|
181
|
+
dotFolders (false) 在文件搜索中包括点文件夹。
|
|
182
|
+
minify (true) 缩小输出 CSS。
|
|
183
|
+
sourceMaps (true) 生成 CSS 源映射。
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### findSCSS(searchDir, options)
|
|
187
|
+
|
|
188
|
+
此函数搜索传递的 `searchDir` 字符串中的所有 SCSS 文件(对于发现 [`compile()`](#compileinputpath-options) 将处理哪些文件很有用)并返回包含其文件路径的数组。
|
|
189
|
+
|
|
190
|
+
选项是布尔值,作为对象属性传递。 例如:
|
|
191
|
+
|
|
192
|
+
```js
|
|
193
|
+
scssToCSS.findSCSS(searchDir, { recursive: false });
|
|
194
|
+
// 返回包含恰好位于 `searchDir` 中的 SCSS 文件的文件路径的数组
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
可能的参数(及其默认设置)有:
|
|
198
|
+
|
|
199
|
+
```
|
|
200
|
+
recursive (true) 如果传递目录路径,则递归搜索嵌套文件。
|
|
201
|
+
verbose (false) 在控制台/终端中显示日志记录。
|
|
202
|
+
dotFolders (false) 在文件搜索中包括点文件夹。
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
<br>
|
|
206
|
+
|
|
207
|
+
## 💖 支持
|
|
208
|
+
|
|
209
|
+
如果这对您有帮助,请考虑[给予 GitHub ⭐](https://github.com/adamlui/js-utils)!
|
|
210
|
+
<br><br>
|
|
211
|
+
|
|
212
|
+
## 🏛️ MIT 许可证
|
|
213
|
+
|
|
214
|
+
**版权所有 © 2023–2024 [刘展鹏 (Adam Lui)](https://github.com/adamlui)**
|
|
215
|
+
|
|
216
|
+
特此免费向任何获得副本的人授予许可本软件和相关文档文件(『软件』),处理在软件中不受限制,包括但不限于权利使用、复制、修改、合并、发布、分发、再许可和/或出售该软件的副本,并允许该软件是提供这样做,但须满足以下条件:
|
|
217
|
+
|
|
218
|
+
上述版权声明和本许可声明应包含在所有软件的副本或重要部分。
|
|
219
|
+
|
|
220
|
+
本软件『按原样』提供,不提供任何形式的明示或保证暗示的,包括但不限于适销性保证,适用于特定目的和非侵权。 在任何情况下都不得作者或版权持有人对任何索赔、损害或其他责任,无论是在合同、侵权或其他方面的行为中,由以下原因引起,出于或与软件或使用或其他交易有关软件。
|
|
221
|
+
|
|
222
|
+
<br>
|
|
223
|
+
|
|
224
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
225
|
+
|
|
226
|
+
<a href="https://github.com/adamlui/js-utils">**家**</a> /
|
|
227
|
+
<a href="https://github.com/adamlui/js-utils/discussions">讨论</a> /
|
|
228
|
+
<a href="#--scss-to-css">回到顶部 ↑</a>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<div align="right">
|
|
2
|
+
<h6>
|
|
3
|
+
<picture>
|
|
4
|
+
<source type="image/svg+xml" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/white/icon32.svg">
|
|
5
|
+
<img height=14 src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/black/icon32.svg">
|
|
6
|
+
</picture>
|
|
7
|
+
简体中文 |
|
|
8
|
+
<a href="../SECURITY.md">English</a> |
|
|
9
|
+
<a href="../zh-tw/SECURITY.md">繁體中文</a>
|
|
10
|
+
</h6>
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
# 🛡️ 安全政策
|
|
14
|
+
|
|
15
|
+
如果您发现漏洞,请打开[安全公告草案](https://github.com/adamlui/js-utils/security/advisories/new)。
|
|
16
|
+
|
|
17
|
+
也欢迎拉取请求,但出于安全原因,请发送电子邮件至 <adam@kudoai.com> 并等待回复后再公开。
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<div align="right">
|
|
2
|
+
<h6>
|
|
3
|
+
<picture>
|
|
4
|
+
<source type="image/svg+xml" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/white/icon32.svg">
|
|
5
|
+
<img height=14 src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/black/icon32.svg">
|
|
6
|
+
</picture>
|
|
7
|
+
繁體中文 |
|
|
8
|
+
<a href="../LICENSE.md">English</a> |
|
|
9
|
+
<a href="../zh-cn/LICENSE.md">简体中文</a>
|
|
10
|
+
</h6>
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
# 🏛️ MIT 许可证
|
|
14
|
+
|
|
15
|
+
**版權所有 © 2023–2024 [刘展鹏 (Adam Lui)](https://github.com/adamlui)**
|
|
16
|
+
|
|
17
|
+
特此免費授予任何取得副本的人許可本軟體和相關文件文件(『軟體』),處理在軟體中不受限制,包括但不限於權利使用、複製、修改、合併、發布、分發、再授權和/或出售該軟體的副本,並允許該軟體是提供這樣做,但須滿足以下條件:
|
|
18
|
+
|
|
19
|
+
上述版權聲明和本許可聲明應包含在所有軟體的副本或重要部分。
|
|
20
|
+
|
|
21
|
+
本軟體『依現況』提供,不提供任何形式的明示或保證暗示的,包括但不限於適銷性保證,適用於特定目的和非侵權。 在任何情況下都不得作者或版權持有人對任何索賠、損害或其他責任,無論是在合約、侵權或其他方面的行為中,由以下原因引起,出於或與軟體或使用或其他交易有關軟體。
|