Last active
July 3, 2016 05:54
-
-
Save cognitom/0ee8754eb2ee3ae3f7d270c9f47f9021 to your computer and use it in GitHub Desktop.
How to use postcss with Riot.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<app> | |
<h1>Riot</h1> | |
<p>A React-like user interface micro-library.</p> | |
<style scoped type="external"> | |
:scope { | |
display: block; | |
} | |
h1 { | |
border-bottom: 1px solid black; | |
flex: auto; | |
} | |
</style> | |
</app> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const | |
co = require('co'), | |
riot = require('riot-compiler'), | |
postcss = require('postcss'), | |
autoprefixer = require('autoprefixer'), | |
fsp = require('fs-promise'), | |
path = require('path') | |
let css = '' | |
// 独自パーサの定義 | |
riot.parsers.css.external = (tagName, str) => { | |
css += riot.style(str, tagName, 'scoped-css') | |
return '' | |
} | |
co(function* (config) { | |
const | |
src = 'src/app.tag', | |
dist = 'dist/app.js', | |
distCss = 'dist/style.css', | |
tag = yield fsp.readFile(src, 'utf8'), // ファイルの読み出し | |
js = riot.compile(tag), // タグのコンパイル | |
p = postcss().use(autoprefixer()), // PostCSSのプラグイン指定 | |
processed = yield p.process(css, { src, distCss }) // PostCSSの処理 | |
yield fsp.mkdirs(path.dirname(dist)) // 書き出し先のフォルダを確保 | |
yield fsp.writeFile(dist, js) // JavaScriptファイルに出力 | |
yield fsp.writeFile(distCss, processed) // CSSファイルに出力 | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app,[riot-tag="app"],[data-is="app"]{ display: block; } app h1,[riot-tag="app"] h1,[data-is="app"] h1{ border-bottom: 1px solid black; -webkit-box-flex: 1; -ms-flex: auto; flex: auto; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
最後のstyle.cssは出力結果です。
やっていることは次の通り。
external
というスタイルのタイプとそのパーサーを用意