Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A plugin that can generate CSS automatically. 一款可以自动生成css的插件!

Notifications You must be signed in to change notification settings

werfun/happycss

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

30 Commits

Repository files navigation

happycss

这是一款可以自动生成css样式的插件,你只需要在 vue中写入 class="w10",或者 react 中 className="w10", 就会自动生成width: 10px;

默认单位为px,如果你需要使用%

请添加如 class="w10p",则会生成 width: 10%

默认生成路径为 /src/assets/css/happycss.css (请确保已经存在css目录)

默认导出路径为 /src/main.js (非该目录,请配置 importPath)

最重要的,插件不影响px2rem使用!!!



This is a plugin that can automatically generate CSS style. You only need to write class= "w10" in vue, and it will automatically generate width: 10px;

The default unit is px, if you need to use%

If you add class= "w10p", you will generate width: 10%

The default generation path is/src/assets/css/happycss.css (make sure that the CSS directory already exists)

The default export path is / src/main.js. (If not this directory, configure importPath)

Most importantly, this plugin do not affect the use of px2rem!!!

a webpack loader for css

Downloads

Install

npm install happycss

or

yarn add happycss

webpack config

const happycss = require('happycss')

module.exports = {
 // ...
 plugins: [
 new happycss({
 // cssPath: '/src/assets/css/happycss.css'
 // importPath: '/src/main.js'
 }),
 ]
}

vue-cli 3.0 vue.config.js

const happycss = require('happycss')

module.exports = {
 // ...
 configureWebpack: {
 plugins: [
 new happycss({
 // cssPath: '/src/assets/css/happycss.css'
 // importPath: '/src/main.js'
 })
 ]
 }
}

The specific rules are as follows

具体规则如下

use(写法) generate(生成)
css .w10 { width: 10px }
class="w10p" .w10 { width: 10% }
class="h10" .h10 { height: 10px }
class="mt10"(mt mr mb ml) .mt { margin-top: 10px }
class="pt10"(pt pr pb pl) .pt { padding-top: 10px }
class="lh10" .lh10 { line-height: 10px }
class="c-fff"(只支持16进制格式) .c-fff { color: #fff }

options

参数

content(内容) function(作用) default(默认值) type
cssPath css生成文件路径 ./src/assets/css/happycss.css String
importPath css导出文件路径 ./src/main.js String
autoImport 是否自动生成import链接 true Boolean

注意事项

1.请勿对生成文件happycss.css文件进行添加操作,因为每次编译,都会生成全新的文件。

2.import 生成路径,默认为系统路径,可手动移至文件顶部。反感路径太长,可配置autoImport 为false后,手动引入css文件

Change Log

0.3.1

  • Support color

  • 增加对color的支持

0.3.0

  • Support react

  • 增加对react的支持 (外部文件新增样式,需要刷新页面)

0.2.0

  • compatible webpack 3.04円.0

  • 兼容webpack 3.0和4.0

0.1.1

  • Increase support for crossing'-','_'in class class names

  • 增加对class类名中 横行'-' 、 '_'的支持

0.1.0

  • Support Webpack 4.0

  • 只支持webpack 4.0

0.0.6

  • auto create happycss.css file

  • 自动生成 happycss.css 文件

License

MIT

About

A plugin that can generate CSS automatically. 一款可以自动生成css的插件!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

AltStyle によって変換されたページ (->オリジナル) /