Git Product home page Git Product logo

qpack's Introduction

qpack

一个 Ques Compoent 命令行管理工具,贯穿Ques Component开发阶段。

安装

$ npm install qpack -g

使用

  • 初始化component

$ qpack init [path]

会自动在path(默认为进程当前的工作目录)初始化main.htmlmian.css,重构同学可以基于这两个文件进行开发

  • 翻译成Ques Comonent

$ qpack tran [src] [dist]

会将src(默认为进程当前的工作目录)中的源文件编译生成到dist(默认为相对于src../#{BlockName},BlockName由分析CSS生成)

进阶功能

开启开发服务器,可使用强大的CSS后置处理功能。

$ qpack app [options] [path]

其中options可设置port,默认为80,如果我们要设置成3000,可以:

$ qpack app -p 3000

path为映射的路径(默认为进程当前的工作目录),如果我们要模拟components/iheader,则:

$ qpack app components/iheader

已集成的CSS后处理技术

Alt text

Alt text

Alt text

为什么使用CSS后置处理技术?

CSS预处理技术应用广泛,例如:SassLESS,为什么不使用CSS预处理技术呢?

简单的说在Component化之后,实际上我们对CSS的嵌套(nested)混入(mixin)函数(function)将远远减少,实际上基于标准的CSS后知处理技术已经够用了,详细的分析请参见:聊聊CSS postproccessors

由于印象笔记最近被有关部门关闭分享,所以请查看这里:#3

qpack's People

Contributors

miniflycn avatar

Stargazers

masx200 avatar 一丝 avatar

Watchers

James Cloos avatar  avatar

qpack's Issues

聊聊CSS postproccessors

阿里妈妈 @一丝 准备发布其CSSGrace,即CSS后处理插件,于是顺便聊聊CSS postprocessors。

从Rework说起

Rework是TJ大神开发的CSS预处理框架。但为什么会出现呢?TJ大神如此回答:

The simple answer is that Rework caters to a different audience, and provide you the flexibility to craft the preprocessor you want, not the choices the author(s) have force on you.
Our goal with Rework contrasts the others, as it does not provide a higher level language within the CSS documents, Rework’s goal is to make those constructs unnecessary, being the most transparent CSS pre-processor out there.

简单地说,就是从之前的特定CSS预处理器,转而成为通用式CSS预处理框架,通过插件,可自定义扩展功能。

我用compass用得正爽,凭什么用你?

  • 工程师喜欢瞎折腾,满足其DIY乐趣

  • 现代前端,多端多屏、需要不同兼容场景下情况下,CSS预处理器需要深度定制,来看看我们没有深度定制的后果:

    1. 我们经常使用@include border-radius;,可你知道compass这个mixin有啥问题么?
      c .btn-default { -webkit-border-radius: 2px } // 仅在 android 2.1, chrome 4, ios_saf 3.2, safari 4 或更早期版本适用 .btn-default { -moz-border-radius: 2px } // 仅在 firefox 3.6 以前版本适用 .btn-default { -ms-border-radius: 2px } // 根本不存在 -ms-border-radius .btn-default { -o-border-radius: 2px } // 这玩意早就淘汰了
    2. 我们也经常用@include transition();,但:
    .course-card .course-agency { -moz-transition: .3s } // 仅在 firefox 15 以前版本适用
    .course-card .course-agency { -o-transition: .3s } // 仅在 opera 12 以前版本适用
  • 嵌套很强大,但某些时候也是灾难

    1. 多层嵌套,代码维护的灾难
      多层嵌套地狱
    2. 多层嵌套导致的单页应用代码性能问题,所以Github的CSS规范明确指明Sass嵌套不允许多余三层(之前我们以为仅仅是维护性原因),有兴趣可以围观下 GitHub's CSS Performance

Autoprefixer革命

在我看来真正带来革命的不是postcss,恰恰是他的核心组件Autoprefixer。让我们看看他到底干了什么?[1]

Working with Autoprefixer is simple: just forget about vendor prefixes and write normal CSS according to the latest W3C specs. You don’t need a special language (like Sass) or remember, where you must use mixins.
Just write normal CSS according to the latest W3C specs and Autoprefixer will produce the code for old browsers.

所以呢?如果我们写了:

a {
    display: flex;
}

则经过Autoprefixer,会变成:

a {
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-box;
    display: -ms-flexbox;
    display: flex;
}

并且这些hack数据是从caniuse获取的,所以能根据你的需要设置你需要兼容的浏览器。Sounds good!这更像polyfill,我们只用按照标准写就好了,polyfill会帮忙处理兼容性,之后如果无需兼容,其会自动去除。

CSSGrace

Make it better!

CSSGrace在我看来主要由于AST的介入,其可能分析出以前preproccessors分析不出来的css错误问题,类似csslint的一些静态分析,以及一丝所说的CSS常见错误,例如:float: left/right 或者 position: absolute 后还写上 display: block,具体参见:http://www.zhihu.com/question/20979831

最后随想

个人感觉未来Web会Web Component化,无论是以W3C标准以HTML为核心的Web Component,还是类似React以Javascript为核心的Web Component,在纵向力度足够细的时候,css样式将趋近与足够简单。

在这种背景下,当处理好作用域的情况下(目前没什么好办法,可能只能将class name写长一点),未来嵌套场景将大大减少,从这一点来看,以前的Sass、LESS等如此强大的预处理器未必是必需品。

[1] 在我的记忆里Autoprefixer是rework的插件(因为当时Autoprefixer是rework的主打功能之一),所以我开挖掘机挖了下,发现的确如此,实际上Autoprefixer在1.0脱离了rework,独立出postcss,具体原因见下:

CSS parser was changed to PostCSS. It allows to add prefixes inside some new or custom at-rules and fix issue with comment in property name. Also it clean Autoprefixer code by moving some common CSS processor code to PostCSS.

Add English doc

Add English doc。
(增加英文文档,方便更多人使用。)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.