将中央支助系统转变为联署材料的工具
雇工吗
想要得到报酬 为你的捐款 CSS-to-JS? 吗?
把你的简历发给 aexp.com (中文(简体) )
目录
* 特性
- 将 CSS 转换为 JS
- 支持多种输入和输出格式(内置代码、文件、目录)
- 生成样式对象为 e6 导出, 选项可拆分为单独的文件
- 反向媒体查询分布
使用量
安装 :
npm install @americanexpress/css-to-js --save-dev
CLI: 爱丽丝
css-to-js <inputPath> <outputPath> (--mediaReverse) (--splitFile | --shakeFile)
Arguments:
inputPath input path to css file or dir of css files outputPath output path to js file or dir Options:
--help --version --mediaReverse reverse mediaQuery style properties --splitFile generate multiple files with exports for each selector in css file
--shakeFile generate single file with exports for each selector in css file
If shakeFile or splitFile is not specified, generate single file with single exported object with selectors in css file as keys
See API for more details.
节点 :
import { convert } from 'css-to-js';
Example Usage:
//Input CSS string, Outputs JS Object
convert(`.myClass { color: 'red' }`);
//Input CSS string, Output file exporting JS Object
convert(`.myClass { color: 'red' }`, { outputType: 'file', outputPath: 'outPath' });
//Input CSS file path, Output file exporting JS Object
convert('absolute-path-to-css-file', { outputType: 'file', outputPath: 'outPath' });
//Input CSS file path, Output file exporting multiple JS Objects
convert('absolute-path-to-css-file', { outputType: 'shakeFile', outputPath: 'outPath' });
//Input CSS file path, Outputs dir of files exporting single JS Objects (If treeshaking not supported)
convert('absolute-path-to-css-file', { outputType: 'splitFile', outputPath: 'outPath' });
//Input Dir path of CSS files, Output array of JS Objects
convert('absolute-path-to-dir');
//Input Dir path of CSS files, Output dir of converted files exporting JS Object
convert('absolute-path-to-dir'', { outputType: 'file', outputPath: 'outPath' });
• API
输入和输出类型选项
确保路径绝对或仅相对于根
| 转换函数 | 输入类型 | 输出类型 |
|---|---|---|
| 转换; | 单一 CSS 文件或 CSS 代码字符串的路径 | JS 风格对象 |
| 转换( css, { 输出类型 : “ 文件 ” , 输出路径 : “ 实例 . js ”) ; | 单一 CSS 文件或 CSS 代码字符串的路径 | 生成 JS 文件 '例. js' , 默认导出 JS 样式对象 |
| 转换( css, { 输出类型 : “ shakeFile” , 输出路径 : “ shakeExample.js' } ); | 单一 CSS 文件或 CSS 代码字符串的路径 | 生成 JS 文件 “ shakeExample.js ” , 并有多处命名的 JS 风格对象导出 |
| 转换( css, { 输出类型 : “ splitFile ” , 输出路径 : “ splitExample ” ) ; | 单一 CSS 文件或 CSS 代码字符串的路径 | 生成目录“ splitExample” , 每个文件有多个文件, 默认导出 JS 样式对象 |
| 转换( dirPath) ; | CSS 文件目录路径 | JS 样式对象阵列 |
| 转换( dirPath, { 输出Type: “文件” , 输出Path: “实例Dir” } ); | CSS 文件目录路径 | 生成 JS 文件目录; 每个文件有一个默认导出 JS 样式对象, 并以相应的 cs 文件命名 |
| 转换( dirPath, { 输出类型 : “ shakeFile ” , 输出类型 : “ shakeExample.js' } ); | CSS 文件目录路径 | 生成 JS 文件目录; 每个文件有多个命名导出 JS 样式对象,并以相应的 cs 文件命名 |
| 转换( dirPath, { 输出类型 : “ splitFile ” , 输出类型 : “ splitExample ” ) ; | CSS 文件目录路径 | 生成目录目录; 每个文件有一个默认导出 JS 样式对象, 并以相应的 fs 文件命名 |
文件转换示例
样本输入 : nav.css
.class1 {
color: 'red';
}
.class2 {
color: 'blue';
}
例1:文件 - 创建一个文件,以一个单一对象导出,代表完全转换的 Css 树
convert(
path.resolve(__dirname, './nav.css'),
{
outputType: 'file',
outputPath: path.resolve(__dirname, '../example1.js')
}
);
输出 : Example1.js
export default {
class1: { color: 'red' },
class2: { color: 'blue' }
}
例2:摇动花样 - 创建多个导出文件, 代表转换的每个选择器
(用于不被使用的摇树样式对象)
convert(
path.resolve(__dirname, './nav.css'),
{
outputType: 'shakeFile',
outputPath: path.resolve(__dirname, '../example2.js')
}
);
输出 : Example2.js
export const class1 = { color: 'red' };
export const class2 = { color: 'blue' };
例3:拆分文件 - 创建多个文件,其导出代表转换的css的每个选择器
(用于排除如果不执行树摇动而不会被使用的样式对象)
convert(
path.resolve(__dirname, './nav.css'),
{
outputType: 'splitFile',
outputPath: path.resolve(__dirname, '../example3')
}
);
输出 : Example3/
class1.js
export default { color: 'red' };
class2.js
export default { color: 'blue' };
媒体倒转
说明: mediaReverse 如果输出类型是 shakeFile 或者说 splitFile
有时将媒体查询中的样式分布到选择器属性中,而不是作为自己的属性,是有用的.
如果 mediaReverse 旗被设定为真实,倒置媒体查询的位置以在属性内.
nav.css
.class1 { color: 'red'; }
@media (min-width:500px) {
.class1 { color: 'blue'; }
}
@media (min-width:1000px) {
.class1 { color: 'green'; }
}
如果未设置反向介质 :
convert(
path.resolve(__dirname, './nav.css'),
{
outputType: 'file',
outputPath: path.resolve(__dirname, '../example4.js')
}
);
Example4.js
export default {
class1: { color: 'red' },
'@media (min-width:500px)': {
class2: { color: 'blue' }
},
'@media (min-width:1000px)': {
class2: { color: 'green' }
}
}
如果媒体逆向设定为 真实数字 :
convert(
path.resolve(__dirname, './nav.css'),
{
outputType: 'file',
outputPath: path.resolve(__dirname, '../example4.js'),
mediaReverse: true
}
);
Example4.js
export default {
class1: { color: 'red' },
class2: {
'@media (min-width:500px)': {
color: 'blue'
},
'@media (min-width:1000px)': {
color: 'green'
}
}
}
基特虎克队
这些命令会在像执行代码这样的普通 git 操作中自动运行.
pre-commit
这个钩子在跑 npm test 之前,允许 承诺被检查.
commit-msg
这个钩子验证您的承诺信息符合 One Amex 的常规 。 见 承诺
消息 节次 捐款额。 。 。 .
捐款
我们欢迎您对吉苏布的美国快递开放源代码社区感兴趣. 美国快递开放管理的任何开源项目的任何贡献者 来源地社区必须接受并签署一项协定,表明同意 条件如下。 除本协定赋予美国快递公司的权利外 以及美国快递公司发行的软件的接收者, 您保留所有 右,头衔,和利息,如果有的话, 对你的贡献。 请 填满 退出协议。 。 。 .
请随意打开拉取请求,看看 捐款额 用于输入详细格式.
许可证
在本项目下提供的任何捐款将受项目 Apache 许可证 2.0。 。 。 .
行为守则
本项目遵循 美国快递社区准则。 。 。 .
通过参与,你们将遵守这些准则.