babel-plugin-custom-console-style
Version:
a babel plugin that changes the output style of console.log
142 lines (119 loc) • 2.36 kB
Markdown
**中文** | [English](./README.md)
`babel-plugin-custom-console-style`是一个可以改变`console.log`输出样式的babel插件
```bash
npm i babel-plugin-custom-console-style -D
```
```js
module.exports = {
plugins: [
"custom-console-style"
]
};
//or传入自定义的样式
module.exports = {
plugins: [
[
"custom-console-style",
{
themeStyle: {
yellow:{
background: "#ffff33",
color: "#000",
border: "1px solid red"
}
}
}
]
]
};
```
```
{
"plugins": [
"custom-console-style"
]
}
//or传入自定义配置
{
"plugins": [
[
"custom-console-style",
{
"themeStyle": {
"yellow":{
"background": "#ffff33",
"color": "#000",
"border": "1px solid red"
}
}
}
]
]
}
```
通过在console.log()后加上注释`//test|red`, `test`是会应用自定义样式的前辍, `red`表示使用red主题, 通过`|`分割, 将设置传递给plugin
```js
console.log("Hello World")//Rain|red
console.log("Hello World")//Rain|blue
console.log("Hello World")//Rain|green
console.log("Hello World")//Rain|pink
```
**在控制台查看**

```js
const defaultStyle = {
background: "#4caf50",
color: "white",
padding: "5px",
"border-radius": "5px"
}
const customThemeStyle = {
red: {
background: "#f44336"
},
green: {
background: "#4caf50"
},
blue: {
background: "#2196f3"
},
pink: {
background: "#ff69b4"
}
}
```
传入以下配置
```js
{
themeStyle:{
yellow:{
background: "#ffff33",
color: "#000",
border: "1px solid red"
},
black:{
background: "#000",
color: "green"
}
}
}
```
使用自定义配置
```js
console.log("Hello World")//Rain|yellow
console.log("Hello World")//Rain|black
```
**在控制台查看**

如果你想添加自己的主题颜色,请联系我