PostCSS 是个什么鬼东西?
<h2 id="articleHeader0" style="box-sizing: border-box; font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; font-weight: 500; line-height: 1.2; color: rgb(51, 51, 51); font-size: 1.75em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); padding-bottom: 10px;">前言</h2><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">最近大漠前辈在群里发关于<code style="box-sizing: border-box; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 0.93em; color: rgb(199, 37, 78); padding: 2px 4px; border-radius: 3px; background-color: rgb(249, 242, 244);">PostCSS</code>的系列文章,但是耗子姐姐又说看了有点云里雾里的感觉,所以这篇文章将按一个思考的角度来理解一下 PostCSS 到底是一个什么东西。</p><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;"><img data-src="/img/bVqy8b" src="https://segmentfault.com/img/bVqy8b" style="box-sizing: border-box; border: 1px solid rgb(221, 221, 221); vertical-align: middle; max-width: 100%; position: static !important; padding: 3px; cursor: pointer; display: inline;"></p><h2 id="articleHeader1" style="box-sizing: border-box; font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; font-weight: 500; line-height: 1.2; color: rgb(51, 51, 51); margin-top: 1.5em; font-size: 1.75em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); padding-bottom: 10px;">一、提出不懂的地方</h2><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">很多时候第一次在网上查询 PostCSS 概念的时候,大家都解释成一个<code style="box-sizing: border-box; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 0.93em; color: rgb(199, 37, 78); padding: 2px 4px; border-radius: 3px; background-color: rgb(249, 242, 244);">后处理器</code>的概念,其实个人觉得这些概念不重要,更为重要的有以下几点:</p><ol style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; margin-left: 3em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;"><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">它本质上是一个什么东西?</p></li><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">它能解决我们什么问题?</p></li><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">它是通过什么方式来解决我们的问题?</p></li><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">它解决我们的问题是为什么?</p></li><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">怎么实现与 <code style="box-sizing: border-box; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 0.93em; color: rgb(199, 37, 78); padding: 2px 4px; border-radius: 3px; background-color: rgb(249, 242, 244);">SASS</code>、<code style="box-sizing: border-box; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 0.93em; color: rgb(199, 37, 78); padding: 2px 4px; border-radius: 3px; background-color: rgb(249, 242, 244);">LESS</code>、<code style="box-sizing: border-box; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 0.93em; color: rgb(199, 37, 78); padding: 2px 4px; border-radius: 3px; background-color: rgb(249, 242, 244);">Stylus</code> 相同的功能(因为它们被经常拿来比较)</p></li><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">它由哪些东西组成?</p></li><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">既然是程序可以用的,那么它的API呢?</p></li></ol><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">Q: 这个时候,你应该会问:<span style="box-sizing: border-box; font-weight: 700;">为什么要将组成和API放到最后呢?</span></p><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">A: 那是因为我们在认识一个不太清楚的东西的时候,第一次肯定是一个直观的认识:它到底有什么用?而不会说,一来就去深入的研究它。不过这里本质还是要先说一下的,先留个印象。</p><h2 id="articleHeader2" style="box-sizing: border-box; font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; font-weight: 500; line-height: 1.2; color: rgb(51, 51, 51); margin-top: 1.5em; font-size: 1.75em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); padding-bottom: 10px;">二、个个击破</h2><h3 id="articleHeader3" style="box-sizing: border-box; font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; font-weight: 500; line-height: 1.2; color: rgb(51, 51, 51); margin-top: 1.5em; font-size: 1.5em;">1. 它本质上是一个什么东西?</h3><ul style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; margin-left: 3em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;"><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">PostCSS 可以直观的理解为:它就是一个<code style="box-sizing: border-box; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 0.93em; color: rgb(199, 37, 78); padding: 2px 4px; border-radius: 3px; background-color: rgb(249, 242, 244);">平台、平台、平台</code>,重要的事情来三遍比较爽,哈哈!</p></li></ul><blockquote style="box-sizing: border-box; padding: 10.5px 21px; margin-top: 1.5em; margin-bottom: 1.5em; border-left-width: 2px; border-left-style: solid; border-left-color: rgb(0, 154, 97); color: rgb(85, 85, 85); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px; background: rgb(246, 246, 246);"><p style="box-sizing: border-box;">为什么说它是一个平台呢?因为我们直接用它,感觉不能干什么事情,但是如果让一些插件在它上面跑,那么将会很强大。</p></blockquote><ul style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; margin-left: 3em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;"><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">PostCSS 提供了一个解析器,它能够将 CSS 解析成抽象语法树(AST)。</p></li></ul><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">上面两条看完后,我们可以理解为下面这个模型。</p><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;"><img data-src="/img/bVqy8j" src="https://segmentfault.com/img/bVqy8j" style="box-sizing: border-box; border: 1px solid rgb(221, 221, 221); vertical-align: middle; max-width: 100%; position: static !important; padding: 3px; cursor: pointer; display: inline;"></p><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">所以说,PostCSS 它需要一个插件系统才能够发挥作用。我们可以通过“插件”来传递AST,然后再把AST转换成一个串,最后再输出到目标文件中去。当然,这里是有API可以用,这里先不讲,免得晕了。</p><h3 id="articleHeader4" style="box-sizing: border-box; font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; font-weight: 500; line-height: 1.2; color: rgb(51, 51, 51); margin-top: 1.5em; font-size: 1.5em;">2. 它能解决我们什么问题?它是通过什么方式来解决我们的问题?</h3><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">上面的图很清晰,但是我还是不知道是个什么东西!所以接下来温和点,直接从代码层面来感官的认识一下。</p><ul style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; margin-left: 3em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;"><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">它能够为 CSS 提供额外的功能;</p></li><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">通过在 PostCSS 这个<code style="box-sizing: border-box; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 0.93em; color: rgb(199, 37, 78); padding: 2px 4px; border-radius: 3px; background-color: rgb(249, 242, 244);">平台</code>上,我们能够开发一些插件,来处理我们的CSS,比如热门的:autoprefixer</p></li><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">我们能够使用JavaScript来开发插件(这点对前端来说很重要)</p></li></ul><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">好吧,看到一个熟悉的单词了:autoprefixer,这里我们就让它来当栗子吧,可能更容易理解一点。</p><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">首先,我们需要做一些准备,安装好需要的东西。</p><pre class="hljs coffeescript" style="box-sizing: border-box; overflow: auto; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 0.93em; padding: 1em; margin-top: 1.5em; margin-bottom: 1.5em; line-height: 1.3; word-break: break-all; color: rgb(101, 123, 131); border: none; border-radius: 3px; max-height: 35em; position: relative;"><code style="box-sizing: border-box; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 1em; color: inherit; border-radius: 0px; white-space: inherit; overflow-wrap: normal; background: none;"><span class="hljs-regexp" style="box-sizing: border-box; color: rgb(42, 161, 152);">//</span> postcss 的命令行工具sudo <span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">npm</span> install-g postcss-cli
<span class="hljs-regexp" style="box-sizing: border-box; color: rgb(42, 161, 152);">//</span> autoprefixer 插件
sudo <span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">npm</span> install -g autoprefixer
</code></pre><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">第一次用命令行能让你更直观去理解它哈,所以请要有一颗折腾的心。</p><pre class="hljs sql" style="box-sizing: border-box; overflow: auto; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 0.93em; padding: 1em; margin-top: 1.5em; margin-bottom: 1.5em; line-height: 1.3; word-break: break-all; color: rgb(101, 123, 131); border: none; border-radius: 3px; max-height: 35em; position: relative;"><code style="box-sizing: border-box; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 1em; color: inherit; border-radius: 0px; white-space: inherit; overflow-wrap: normal; background: none;">// 1. 先看下这个命令有哪些参数可以用
postcss <span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">--help</span>
Usage: /usr/local/bin/postcss -<span class="hljs-operator" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">use</span> <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">plugin</span> [<span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">--config|-c config.json] [--output|-o</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">output</span>.css] [<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">input</span>.css]
选项:
-c, <span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">--config JSON file with plugin configuration</span>
-u, <span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">--use postcss plugin name (can be used multiple times)</span>
-o, <span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">--output Output file (stdout if not provided)</span>
-d, <span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">--dir Output directory</span>
-r, <span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">--replace Replace input file(s) with generated output </span>
-s, <span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">--syntax Alternative input syntax parser</span>
-p, <span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">--parser Alternative CSS parser</span>
-t, <span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">--stringifierAlternative output stringifier</span>
-w, <span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">--watch auto-recompile when detecting source changes</span>
-v, <span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">--version 显示版本号 </span>
-h, <span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">--help 显示帮助信息 </span>
示例:
postcss <span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">--use autoprefixer -c Use autoprefixer as a postcss plugin</span>
options.json -o screen.css screen.css
postcss <span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">--use autoprefixer Pass plugin parameters in</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">--autoprefixer.browsers "> 5%" -o plugin.option notation</span>
screen.css screen.css
postcss -u postcss-cachify -u <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">Use</span> multiple plugins <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">and</span> multiple
autoprefixer -d build *.css <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">input</span> files
Please specify <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">at</span> <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">least</span> one <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">plugin</span> name.
</span></code></pre><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">PS: 我贴出来是方便大家在看的时候不用电脑……^_^</p><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">好吧,先看一下文件目录,这里我只说一下比较好写的方式,就是将一些参数配置到配置文件中去。</p><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;"><img data-src="/img/bVqy8m" src="https://segmentfault.com/img/bVqy8m" style="box-sizing: border-box; border: 1px solid rgb(221, 221, 221); vertical-align: middle; max-width: 100%; position: static !important; padding: 3px; cursor: pointer; display: inline;"></p><pre class="hljs cs" style="box-sizing: border-box; overflow: auto; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 0.93em; padding: 1em; margin-top: 1.5em; margin-bottom: 1.5em; line-height: 1.3; word-break: break-all; color: rgb(101, 123, 131); border: none; border-radius: 3px; max-height: 35em; position: relative;"><code style="box-sizing: border-box; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 1em; color: inherit; border-radius: 0px; white-space: inherit; overflow-wrap: normal; background: none;"><span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// config.json: 所有的配置</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// p.json: 仅有 autoprefixer 插件的配置</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// config.json 的内容</span>
{
<span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">"use"</span>: [<span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">"autoprefixer"</span>],
<span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">"input"</span>: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">"src/index.css"</span>,
<span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">"output"</span>: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">"index.css"</span>,
<span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">"autoprefixer"</span>: {
<span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">"browsers"</span>: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">"> 5%"</span>
}
}
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// p.json 的内容</span>
{
<span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">"autoprefixer"</span>: {
<span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">"browsers"</span>: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">"> 5%"</span>
}
}
</code></pre><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">接下来我们在终端里面输入:</p><pre class="hljs cs" style="box-sizing: border-box; overflow: auto; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 0.93em; padding: 1em; margin-top: 1.5em; margin-bottom: 1.5em; line-height: 1.3; word-break: break-all; color: rgb(101, 123, 131); border: none; border-radius: 3px; max-height: 35em; position: relative;"><code style="box-sizing: border-box; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 1em; color: inherit; border-radius: 0px; white-space: inherit; overflow-wrap: normal; background: none;"><span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// 最简洁的方式</span>
postcss -c config.json
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// 稍微复杂一点的方式,这里要用 -i 参数,help里面没有,我是从config.json里面的配置猜出来的,官方的那个写法出不来</span>
postcss -u autoprefixer -c p.json -i src/index.css -o index.css
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// 最复杂的方式</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// 还是不写比较好。。。</span>
</code></pre><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">跟平时想到的效果一样:</p><pre class="hljs perl" style="box-sizing: border-box; overflow: auto; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 0.93em; padding: 1em; margin-top: 1.5em; margin-bottom: 1.5em; line-height: 1.3; word-break: break-all; color: rgb(101, 123, 131); border: none; border-radius: 3px; max-height: 35em; position: relative;"><code style="box-sizing: border-box; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 1em; color: inherit; border-radius: 0px; white-space: inherit; overflow-wrap: normal; background: none;">
// src/<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">index</span>.css 中的源码
<span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">`* {
transition: all .1s;
}`</span>
// 转换过后的代码 <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">index</span>.css
<span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">`* {
-webkit-transition: all .1s;
transition: all .1s;
}`</span>
</code></pre><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">好吧,现在肯定就对 PostCSS 有一个感官的认识了,接下来就是需要自己动手去用一下 <code style="box-sizing: border-box; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 0.93em; color: rgb(199, 37, 78); padding: 2px 4px; border-radius: 3px; background-color: rgb(249, 242, 244);">cssnext</code> 这个插件了~看会发生什么,这里就不写了,也挺好用的,不过应该还是草案状态。</p><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">我们开发不可能用命令行吧,所以这里再接着介绍代码编写,然后用 node 去执行文件的方式。直接上代码吧。</p><pre class="hljs javascript" style="box-sizing: border-box; overflow: auto; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 0.93em; padding: 1em; margin-top: 1.5em; margin-bottom: 1.5em; line-height: 1.3; word-break: break-all; color: rgb(101, 123, 131); border: none; border-radius: 3px; max-height: 35em; position: relative;"><code style="box-sizing: border-box; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 1em; color: inherit; border-radius: 0px; white-space: inherit; overflow-wrap: normal; background: none;"><span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// 1. 先安装一下需要的库</span>
npm install postcss --save-dev
npm install autoprefixer --save-dev
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// 2. 其实应该先看看 postcss 的 package.json 文件,来看看包含了些什么,留个印象</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// 3. p.js 中的代码</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">var</span> postcss = <span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">require</span>(<span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">'postcss'</span>);
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">var</span> autoprefixer = <span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">require</span>(<span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">'autoprefixer'</span>);
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">var</span> fs = <span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">require</span>(<span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">'fs'</span>);
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">var</span> css = <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">'* { transition: all .1s; }'</span>;
postcss()
.process(css)
.then(<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">function</span><span class="hljs-params" style="box-sizing: border-box;">(result)</span> </span>{
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// 这一行是学习的时候需要的,看一下到底对象里面包含什么</span>
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">console</span>.log(result);
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">if</span> (result.css) {
fs.writeFileSync(<span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">'index.css'</span>, result.css);
}
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">if</span> (result.map) {
fs.writeFileSync(<span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">'index.css.map'</span>, result.map);
}
});
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// 4. 执行 p.js</span>
node p
</code></pre><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">好吧,最后的结果和之前用命令行的方式一样,只不过过程不同。这样下来应该对 PostCSS 有了更多的感觉了吧。还没完,不用慌~我们还需要提出一个问题,我都有 <code style="box-sizing: border-box; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 0.93em; color: rgb(199, 37, 78); padding: 2px 4px; border-radius: 3px; background-color: rgb(249, 242, 244);">SASS</code> 等预处理器了,还拿它来不是又给前端届添乱么?因为这2年东西确实太多了~</p><blockquote style="box-sizing: border-box; padding: 10.5px 21px; margin-top: 1.5em; margin-bottom: 1.5em; border-left-width: 2px; border-left-style: solid; border-left-color: rgb(0, 154, 97); color: rgb(85, 85, 85); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px; background: rgb(246, 246, 246);"><p style="box-sizing: border-box;">记住一句话:存在即合理</p></blockquote><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">既然合理,那么我们就看看它有什么优势呗~</p><h3 id="articleHeader5" style="box-sizing: border-box; font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; font-weight: 500; line-height: 1.2; color: rgb(51, 51, 51); margin-top: 1.5em; font-size: 1.5em;">3. 它解决我们的问题是为什么?优势何在?</h3><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">比如,我们用 SASS 来处理 box-shadow 的前缀,我们需要这样写:</p><pre class="hljs php" style="box-sizing: border-box; overflow: auto; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 0.93em; padding: 1em; margin-top: 1.5em; margin-bottom: 1.5em; line-height: 1.3; word-break: break-all; color: rgb(101, 123, 131); border: none; border-radius: 3px; max-height: 35em; position: relative;"><code style="box-sizing: border-box; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 1em; color: inherit; border-radius: 0px; white-space: inherit; overflow-wrap: normal; background: none;"><span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">/* CSS3 box-shadow */</span>
@mixin box-shadow(<span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$top</span>, <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$left</span>, <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$blur</span>, <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$size</span>, <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$color</span>, <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$inset</span>: <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">false</span>) {
@<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">if</span> <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$inset</span> {
-webkit-box-shadow: inset <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$top</span> <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$left</span> <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$blur</span> <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$size</span> <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$color</span>;
box-shadow: inset <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$top</span> <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$left</span> <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$blur</span> <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$size</span> <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$color</span>;
} @<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">else</span> {
-webkit-box-shadow: <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$top</span> <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$left</span> <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$blur</span> <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$size</span> <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$color</span>;
box-shadow: <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$top</span> <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$left</span> <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$blur</span> <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$size</span> <span class="hljs-variable" style="box-sizing: border-box; color: rgb(181, 137, 0);">$color</span>;
}
}
</code></pre><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">使用 PostCSS 我们只需要按标准的 CSS 来写就行了,因为最后 autoprefixer 会帮我们做添加这个事情~</p><pre class="hljs http" style="box-sizing: border-box; overflow: auto; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 0.93em; padding: 1em; margin-top: 1.5em; margin-bottom: 1.5em; line-height: 1.3; word-break: break-all; color: rgb(101, 123, 131); border: none; border-radius: 3px; max-height: 35em; position: relative;"><code style="box-sizing: border-box; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 1em; color: inherit; border-radius: 0px; white-space: inherit; overflow-wrap: normal; background: none;"><span class="hljs-attribute" style="box-sizing: border-box; color: rgb(181, 137, 0);">box-shadow</span>: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">0 0 3px 5px rgba(222, 222, 222, .3);</span>
</code></pre><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">所以,这里就出现了一个经常大家说的未来编码的问题。实际上,PostCSS 改变的是一种开发模式。</p><ul style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; margin-left: 3em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;"><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">SASS等工具:源代码 -> 生产环境 CSS</p></li><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">PostCSS:源代码 -> 标准 CSS -> 生产环境 CSS</p></li></ul><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">这样能体会出优势吧,但是目前大家都是 SASS + PostCSS 这样的开发模式,其实我认为是不错的,取长补短嘛,当然,在 PostCSS 平台上都是可以做到的,只是目前这个过渡期,这样更好,更工程化。接下来我就介绍一些方法来纯粹是用 PostCSS。</p><h3 id="articleHeader6" style="box-sizing: border-box; font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; font-weight: 500; line-height: 1.2; color: rgb(51, 51, 51); margin-top: 1.5em; font-size: 1.5em;">4. 怎么实现与 SASS、LESS、Stylus 相同的功能</h3><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">其实这一节我都不需要写了~列一下插件就行了,因为插件才是实现,PostCSS 只是提供了一个平台。</p><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">其实可以去官方看看:<a href="https://github.com/postcss/postcss" target="_blank" style="box-sizing: border-box; color: rgb(0, 154, 97); text-decoration: none; outline: 0px; background: transparent;">插件系统</a><br style="box-sizing: border-box;">这里列几个便于理解的插件</p><ul style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; margin-left: 3em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;"><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">postcss-each</p></li><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">postcss-for</p></li><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">postcss-mixins</p></li><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">postcss-extend</p></li></ul><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">从名字就能看出来了吧~应该很好理解。</p><h3 id="articleHeader7" style="box-sizing: border-box; font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; font-weight: 500; line-height: 1.2; color: rgb(51, 51, 51); margin-top: 1.5em; font-size: 1.5em;">5. 它由哪些东西组成?</h3><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">其实从官方介绍来看,只包含以下内容:</p><ol style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; margin-left: 3em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;"><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">CSS Parser</p></li><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">CSS 节点树 API</p></li><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">source map 生成器</p></li><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">生成节点树串</p></li></ol><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">英文不太好 == ,就这 4 部分吧,从第一个图其实也能够看出来。</p><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">其中的 I/O 体现在什么地方呢?好吧,很容易想到,主要体现在:</p><ul style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; margin-left: 3em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;"><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">Input: <span style="box-sizing: border-box; font-weight: 700;">插件程式</span>和<span style="box-sizing: border-box; font-weight: 700;">CSS Parser</span></p></li><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">Output: <span style="box-sizing: border-box; font-weight: 700;">生成节点树串</span></p></li></ul><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">CSS Parser 可以理解为一个内部过程,而插件程式主要体现在:</p><pre class="hljs css" style="box-sizing: border-box; overflow: auto; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 0.93em; padding: 1em; margin-top: 1.5em; margin-bottom: 1.5em; line-height: 1.3; word-break: break-all; color: rgb(101, 123, 131); border: none; border-radius: 3px; max-height: 35em; position: relative;"><code style="box-sizing: border-box; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 1em; color: inherit; border-radius: 0px; white-space: inherit; overflow-wrap: normal; background: none;"><span class="hljs-tag" style="box-sizing: border-box; color: rgb(133, 153, 0);">postcss</span>(<span class="hljs-attr_selector" style="box-sizing: border-box; color: rgb(203, 75, 22);">[ autoprefixer ]</span>)
</code></pre><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">最后生成的节点树串体现在:</p><pre class="hljs javascript" style="box-sizing: border-box; overflow: auto; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 0.93em; padding: 1em; margin-top: 1.5em; margin-bottom: 1.5em; line-height: 1.3; word-break: break-all; color: rgb(101, 123, 131); border: none; border-radius: 3px; max-height: 35em; position: relative;"><code style="box-sizing: border-box; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 1em; color: inherit; border-radius: 0px; white-space: inherit; overflow-wrap: normal; background: none;">postcss().process().then(<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">function</span> <span class="hljs-params" style="box-sizing: border-box;">(result)</span> </span>{
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// 就是这里了</span>
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">console</span>.log(result.css);
});
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// 现在我贴一下上面 result 对象的一个输出结果</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// 这里我多引入了一个 cssnano 插件</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// 改变的代码就这点,为了更全的看 result</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">var</span> opts = {
from: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">'src/index.css'</span>,
to: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">'index.css'</span>,
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// 配置 map</span>
map: { inline: <span class="hljs-literal" style="box-sizing: border-box;">false</span> }
};
postcss([ autoprefixer, cssnano() ]).process(css, opts)
Result {
processor: Processor {
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// 处理器的版本号</span>
version: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">'5.0.10'</span>,
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// 加载的一堆插件</span>
plugins: [
[<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>], [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>], [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>], [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>], [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>],
[<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>], [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>], [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>], [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>], [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>],
[<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>], [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>], [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>], [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>], [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>],
[<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>], [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>], [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>], [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>], [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>],
[<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>], [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>], [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>], [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>], [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>],
[<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>], [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>]
]
},
messages: [],
root: Root {
raws: {
semicolon: <span class="hljs-literal" style="box-sizing: border-box;">false</span>,
after: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">''</span>
},
type: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">'root'</span>,
nodes: [
[<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>]
],
source: {
input: [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>],
start: [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>]
},
_autoprefixerDisabled: <span class="hljs-literal" style="box-sizing: border-box;">false</span>,
_autoprefixerPrefix: <span class="hljs-literal" style="box-sizing: border-box;">false</span>,
rawCache: {
colon: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">':'</span>,
indent: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">''</span>,
beforeDecl: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">''</span>,
beforeRule: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">''</span>,
beforeOpen: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">''</span>,
beforeClose: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">''</span>,
beforeComment: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">''</span>,
after: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">''</span>,
emptyBody: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">''</span>,
commentLeft: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">''</span>,
commentRight: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">''</span>
}
},
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// 我们代码中配置 opts 变量</span>
opts: {
from: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">'src/index.css'</span>,
to: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">'index.css'</span>
},
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// 这就是重新生成的 节点树串</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// 这里有自动补全和高效压缩的效果</span>
css: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">'*{-webkit-transition:all .1s;transition:all .1s}'</span>,
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// map的文件的配置</span>
map:
SourceMapGenerator {
_file: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">'index.css'</span>,
_sourceRoot: <span class="hljs-literal" style="box-sizing: border-box;">null</span>,
_skipValidation: <span class="hljs-literal" style="box-sizing: border-box;">false</span>,
_sources: ArraySet { _array: [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>], _set: [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>] },
_names: ArraySet { _array: [], _set: {} },
_mappings: MappingList { _array: [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>], _sorted: <span class="hljs-literal" style="box-sizing: border-box;">true</span>, _last: [<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Object</span>] },
_sourcesContents: { <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">'$src/index.css'</span>: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">'* { transition: all .1s; }'</span> } },
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(147, 161, 161);">// 这里应该是链式要用的吧,暂时不深究</span>
lastPlugin: {
[<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">Function</span>]
postcssPlugin: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">'cssnano-reset-stylecache'</span>,
postcssVersion: <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">'5.0.10'</span>
}
}
</code></pre><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">其实吧,这样有点抽象的,还是来看熟悉的 API 吧。</p><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">这里出现了 sourcemap,说明 PostCSS 中的转换功能是它必备的,但是必备并不等于:<span style="box-sizing: border-box; font-weight: 700;">源代码与目标代码不能完全一致</span>。</p><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">这里吐槽一下 Chrome 的 sourcemap 功能,一坨屎!下面看看 firefox 里面的效果吧。</p><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;"><img data-src="/img/bVqy8H" src="https://segmentfault.com/img/bVqy8H" style="box-sizing: border-box; border: 1px solid rgb(221, 221, 221); vertical-align: middle; max-width: 100%; position: static !important; padding: 3px; cursor: pointer; display: inline;"></p><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">这里 firefox 里面就自动映射了<span style="box-sizing: border-box; font-weight: 700;">源文件</span>,非常不错!</p><h3 id="articleHeader8" style="box-sizing: border-box; font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; font-weight: 500; line-height: 1.2; color: rgb(51, 51, 51); margin-top: 1.5em; font-size: 1.5em;">6. 既然是程序可以用的,那么它的API呢?</h3><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">其实官方有 API 的详细解释,我看了一下,一看就明白了,就不再花时间介绍了,大家可以去看看,这样会知道,原来如此~</p><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">PS: 大家可以先看看 Node Common 和 Node相关的,然后再看 plugin</p><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;"><a href="https://github.com/postcss/postcss/blob/master/docs/api.md" target="_blank" style="box-sizing: border-box; color: rgb(0, 154, 97); text-decoration: none; outline: 0px; background: transparent;">官方API</a></p><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">这里看一个 DEMO,主要做 rem 和 px 单位之间的互换,加入 processors 就可以用了,很方便:</p><pre class="hljs javascript" style="box-sizing: border-box; overflow: auto; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 0.93em; padding: 1em; margin-top: 1.5em; margin-bottom: 1.5em; line-height: 1.3; word-break: break-all; color: rgb(101, 123, 131); border: none; border-radius: 3px; max-height: 35em; position: relative;"><code style="box-sizing: border-box; font-family: "Source Code Pro", Consolas, Menlo, Monaco, "Courier New", monospace; font-size: 1em; color: inherit; border-radius: 0px; white-space: inherit; overflow-wrap: normal; background: none;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">var</span> custom = <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">function</span><span class="hljs-params" style="box-sizing: border-box;">(css, opts)</span></span>{
css.eachDecl(<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">function</span><span class="hljs-params" style="box-sizing: border-box;">(decl)</span></span>{
decl.value = decl.value.replace(<span class="hljs-regexp" style="box-sizing: border-box; color: rgb(42, 161, 152);">/\d+rem/</span>, <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">function</span><span class="hljs-params" style="box-sizing: border-box;">(str)</span></span>{
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(133, 153, 0);">return</span> <span class="hljs-number" style="box-sizing: border-box; color: rgb(42, 161, 152);">16</span> * <span class="hljs-built_in" style="box-sizing: border-box; color: rgb(38, 139, 210);">parseFloat</span>(str) + <span class="hljs-string" style="box-sizing: border-box; color: rgb(42, 161, 152);">"px"</span>;
});
});
};
</code></pre><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">开发插件可以看一下 <a href="https://github.com/postcss/postcss/blob/master/docs/guidelines/plugin.md" target="_blank" style="box-sizing: border-box; color: rgb(0, 154, 97); text-decoration: none; outline: 0px; background: transparent;">官方插件指南</a></p><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">更细致的地方,之后有时间的时候再写写 ^_^ 一说技术就停不下来了~</p><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">大家在问?我怎么在工程上应用它呢?好吧,使用 gulp, grunt, webpack 都是可以的,我觉得都理解了 PostCSS ,使用这些就很简单了,一查资料,拷贝一份配置就可以开始用了~就这样吧,下次再结合 react 来介绍一下一个叫: postcss-js 的插件,看上去还不错,还没深入用,用到的时候再分享吧。</p><p style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">其实我也是初学者,只是用了自己的学习方法来梳理成文章,下面都是我看过的文章,部分是引用的。这里就不全部举例了,看的文章有点多。。。</p><h2 id="articleHeader9" style="box-sizing: border-box; font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; font-weight: 500; line-height: 1.2; color: rgb(51, 51, 51); margin-top: 1.5em; font-size: 1.75em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); padding-bottom: 10px;">参考的文章</h2><ul style="box-sizing: border-box; margin-top: 1.5em; margin-bottom: 1.5em; margin-left: 3em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;"><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">最权威的初认识 <a href="https://github.com/postcss/postcss" target="_blank" style="box-sizing: border-box; color: rgb(0, 154, 97); text-decoration: none; outline: 0px; background: transparent;"></a><a href="https://github.com/postcss/postcss" target="_blank" style="box-sizing: border-box; color: rgb(0, 154, 97); text-decoration: none; outline: 0px; background: transparent;">https://github.com/postcss/postcss</a></p></li><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">一个不错的东西 rework <a href="https://github.com/reworkcss" target="_blank" style="box-sizing: border-box; color: rgb(0, 154, 97); text-decoration: none; outline: 0px; background: transparent;"></a><a href="https://github.com/reworkcss" target="_blank" style="box-sizing: border-box; color: rgb(0, 154, 97); text-decoration: none; outline: 0px; background: transparent;">https://github.com/reworkcss</a></p></li><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">理解 AST 等插件解析技术 <a href="http://rapheal.sinaapp.com/category/js/uglify%E6%BA%90%E7%A0%81/" target="_blank" style="box-sizing: border-box; color: rgb(0, 154, 97); text-decoration: none; outline: 0px; background: transparent;"></a><a href="http://rapheal.sinaapp.com/category/js/uglify%E6%BA%90%E7%A0%81/" target="_blank" style="box-sizing: border-box; color: rgb(0, 154, 97); text-decoration: none; outline: 0px; background: transparent;">http://rapheal.sinaapp.com/category/js/uglify%E6%BA%90%E7%A0%81/</a></p></li><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">大漠的系列文章,应用型很强,推荐 <a href="http://www.w3cplus.com/blog/tags/517.html" target="_blank" style="box-sizing: border-box; color: rgb(0, 154, 97); text-decoration: none; outline: 0px; background: transparent;"></a><a href="http://www.w3cplus.com/blog/tags/517.html" target="_blank" style="box-sizing: border-box; color: rgb(0, 154, 97); text-decoration: none; outline: 0px; background: transparent;">http://www.w3cplus.com/blog/tags/517.html</a></p></li><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">一个年龄差不多的开发者的解释 <a href="http://acgtofe.com/posts/2015/05/modular-transforming-with-postcss/" target="_blank" style="box-sizing: border-box; color: rgb(0, 154, 97); text-decoration: none; outline: 0px; background: transparent;"></a><a href="http://acgtofe.com/posts/2015/05/modular-transforming-with-postcss/" target="_blank" style="box-sizing: border-box; color: rgb(0, 154, 97); text-decoration: none; outline: 0px; background: transparent;">http://acgtofe.com/posts/2015/05/modular-transforming-with-postcss/</a></p></li><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">一篇稍微理论化解释的文章 <a href="http://www.oschina.net/translate/its-time-for-everyone-to-learn-about-postcss?cmp" target="_blank" style="box-sizing: border-box; color: rgb(0, 154, 97); text-decoration: none; outline: 0px; background: transparent;"></a><a href="http://www.oschina.net/translate/its-time-for-everyone-to-learn-about-postcss?cmp" target="_blank" style="box-sizing: border-box; color: rgb(0, 154, 97); text-decoration: none; outline: 0px; background: transparent;">http://www.oschina.net/translate/its-time-for-everyone-to-learn-about-postcss?cmp</a></p></li><li style="box-sizing: border-box; margin-top: 0.3em; margin-bottom: 0.3em; margin-left: 0px;"><p style="box-sizing: border-box;">一个开发模式简单的优劣比较 <a href="http://caibaojian.com/css-processor.html" target="_blank" style="box-sizing: border-box; color: rgb(0, 154, 97); text-decoration: none; outline: 0px; background: transparent;"></a><a href="http://caibaojian.com/css-processor.html" target="_blank" style="box-sizing: border-box; color: rgb(0, 154, 97); text-decoration: none; outline: 0px; background: transparent;">http://caibaojian.com/css-processor.html</a></p></li></ul><p style="box-sizing: border-box; margin-top: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">大家也可以直接阅读我的博客:<a href="http://www.60sky.com/" target="_blank" style="box-sizing: border-box; color: rgb(0, 154, 97); text-decoration: none; outline: 0px; background: transparent;"></a><a href="http://www.60sky.com/" target="_blank" style="box-sizing: border-box; color: rgb(0, 154, 97); text-decoration: none; outline: 0px; background: transparent;">http://www.60sky.com</a></p><p style="box-sizing: border-box; margin-top: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;"><br></p><p style="box-sizing: border-box; margin-top: 1.5em; color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; line-height: 22.4px;">来源:https://segmentfault.com/a/1190000003909268</p><p></p>
页:
[1]