1.0.2 • Published 11 months ago

generator-metaclass-webpack-plugin v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

generator-metaclass-webpack-plugin

这是一个基于 webpack 的生成原子式 css class 工具

目前测试在 vue2、vue3 基于webpack项目中工作正常

使用

  1. npm i generator-metaclass-webpack-plugin -D

  2. vue.config.js 中配置

const generatorMetaClassPlugin = require('generator-metaclass-webpack-plugin');

module.exports = {
    configureWebpack: {
        module: {
            rules: [
                {
                    test: /\.vue$/i,
                    use: [generatorMetaClassPlugin.loader]
                }
            ]
        },
        plugins: [
            new generatorMetaClassPlugin()
        ]
      }
}

在 .vue 文件中使用

只需要书写符合规则的 class,就会自动生成 generator.css,插入 html 的 head

例如:

<template>
    <h1 class="margin_10-15-20-25 color_#f40"></h1>
</template>

在生成的 generator.css 中内容:

.margin_10_15_20_25{
    margin: 10px 15px 20px 25px;
}
.color_0xf40{
    color: #f40;
}

规则

属性名称

  1. 所有的单个单词的属性都可以直接单词,其中有些可以简写 例如:
属性简写
backgroundbackground, bg
heightheight, h
widthwidth, w
opacityopacity
  1. 双单词属性几乎可以使用第一个单词首字母+后一个完整单词的形式来书写,但有六个是特殊的:max-heightmax-widthmin-heightmin-widthbackground-colorbackground-image 例如:
属性简写
max-heightmaxh
max-widthmaxw
min-heightminh
min-widthminw
align-contentac、acontent
align-itemsai、aitems
align-selfas、aself
align-namean、aname
backface-visibilitybv、bvisibility
background-attachmentba、battachment
background-colorbc、bgc
background-imagebi、bgimage
background-originbo、borigin
background-positionbp、bposition
background-sizebz、bsize
background-bottombb、bbottom
border-leftbl、bleft
border-rightbr、bright
border-stylebs、bstyle
border-topbt、btop
border-topbt、btop
clip-pathcp、cpath
column-countcc、ccount
column-fillcf、cfill
column-gapcg、cgap
column-rulecr、crule
column-spancs、cspan
column-widthcw、cwidth
counter-incrementci、cincrement
empty-cellsec、ecells
flex-basisfb、fbasis
flex-directionfd、fdirection
flex-growfg、fgrow
font-familyff、ffamily
font-kerningfk、fkerning
font-sizefs、fsize
font-variantfv、fvariant
font-weightfw、fweight
grid-areaga、garea
grid-columngc、gcolumn
grid-gapgg、ggap
grid-rowgr、grow
grid-templategt、gtemplate
hanging-punctuationhp、hpunctuation
image-renderingir、irendering
justify-contentjc、jcontent
justify-itemji、jitems
justify-selfjs、jself
letter-spacingls、lspacing
line-breaklb、lbreak
line-heightlh、lheight
list-stylels、lstyle
margin-bottommb、mbottom
margin-leftml、mleft
margin-rightmr、mright
margin-topmt、mtop
object-fitof、ofit
object-positionop、oposition
outline-coloroc、ocolor
outline-offsetoo、ooffset
outline-styleos、ostyle
overflow-wrapow、owrap
padding-bottompb、pbottom
padding-leftpl、pleft
padding-rightpr、pright
padding-toppt、ptop
perspective-originpo、porigin
pointer-eventspe、pevents
scroll-behaviorsb、sbehavior
tab-sizebs、bsize
tab-layouttl、tlayout
text-alignta、talign
text-decorationtd、tdecoration
text-indentti、tindent
text-justifytj、tjustify
text-shadowts、tshadow
text-transformtt、ttransform
transform-originto、torigin
transition-propertytp、tproperty
unicode-bidiub、ubidi
user-selectus、uselect
vertical-alignva、valign
white-spacews、wspace
word-breakwb、wbreak
word-wrapww、wwrap
writing-modewm、wmode
z-indexzi、zindex
  1. 多单词属性,都可以使用单词首字母进行简写 例如:
属性简写
border-top-colorbtc
grid-row-gapgra

属性值

  1. 数字结尾,默认添加px作为单位
    • 如:w_100 得到 .w_100{width: 100px}
  2. 不需要添加单位,请使用 n 作为结尾
    • 如:flex_1n 得到 .flex_1{flex: 1}
  3. 如果你想以 % 作为单位,请以 p 作为结尾
    • 如:h_10p 得到 .h_10p{height: 10%}
  4. 暂不支持 calc()rgb()rgba()url() 等css函数,后续可能会考虑支持
1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago