Skip to content

Commit

Permalink
feat(plugin-stylus): 增加 stylus 处理插件
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Jun 18, 2018
1 parent 0e16b29 commit cf0ee58
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/taro-plugin-stylus/index.js
@@ -0,0 +1,33 @@
const fs = require('fs')
const path = require('path')
const stylus = require('stylus')

module.exports = function compileStylus (content, file, config) {
return new Promise((resolve, reject) => {
if (!content && !fs.existsSync(file)) {
return resolve({
css: ''
})
}
if (!content) {
content = fs.readFileSync(file).toString()
}
const opath = path.parse(file)
config.paths = [opath.dir]
config.filename = opath.base
const instance = stylus(content)
for (const k in config) {
instance.set(k, config[k])
}
let imports = instance.deps()
instance.render((err, css) => {
if (err) {
return reject(err)
}
resolve({
css,
imports
})
})
})
}
21 changes: 21 additions & 0 deletions packages/taro-plugin-stylus/package.json
@@ -0,0 +1,21 @@
{
"name": "@tarojs/plugin-stylus",
"version": "0.0.51",
"description": "Taro 编译 stylus 文件",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/NervJS/taro.git"
},
"keywords": [
"taro"
],
"author": "luckyadam",
"license": "MIT",
"dependencies": {
"stylus": "^0.54.5"
}
}
113 changes: 113 additions & 0 deletions packages/taro-plugin-stylus/yarn.lock
@@ -0,0 +1,113 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


amdefine@>=0.0.4:
version "1.0.1"
resolved "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5"

balanced-match@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"

brace-expansion@^1.1.7:
version "1.1.11"
resolved "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
dependencies:
balanced-match "^1.0.0"
concat-map "0.0.1"

concat-map@0.0.1:
version "0.0.1"
resolved "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"

css-parse@1.7.x:
version "1.7.0"
resolved "https://registry.npmjs.org/css-parse/-/css-parse-1.7.0.tgz#321f6cf73782a6ff751111390fc05e2c657d8c9b"

debug@*:
version "3.1.0"
resolved "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
dependencies:
ms "2.0.0"

fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"

glob@7.0.x:
version "7.0.6"
resolved "https://registry.npmjs.org/glob/-/glob-7.0.6.tgz#211bafaf49e525b8cd93260d14ab136152b3f57a"
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
inherits "2"
minimatch "^3.0.2"
once "^1.3.0"
path-is-absolute "^1.0.0"

inflight@^1.0.4:
version "1.0.6"
resolved "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9"
dependencies:
once "^1.3.0"
wrappy "1"

inherits@2:
version "2.0.3"
resolved "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"

minimatch@^3.0.2:
version "3.0.4"
resolved "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
dependencies:
brace-expansion "^1.1.7"

minimist@0.0.8:
version "0.0.8"
resolved "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"

mkdirp@0.5.x:
version "0.5.1"
resolved "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
dependencies:
minimist "0.0.8"

ms@2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"

once@^1.3.0:
version "1.4.0"
resolved "https://registry.npmjs.org/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
dependencies:
wrappy "1"

path-is-absolute@^1.0.0:
version "1.0.1"
resolved "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"

sax@0.5.x:
version "0.5.8"
resolved "https://registry.npmjs.org/sax/-/sax-0.5.8.tgz#d472db228eb331c2506b0e8c15524adb939d12c1"

source-map@0.1.x:
version "0.1.43"
resolved "https://registry.npmjs.org/source-map/-/source-map-0.1.43.tgz#c24bc146ca517c1471f5dacbe2571b2b7f9e3346"
dependencies:
amdefine ">=0.0.4"

stylus@^0.54.5:
version "0.54.5"
resolved "https://registry.npmjs.org/stylus/-/stylus-0.54.5.tgz#42b9560931ca7090ce8515a798ba9e6aa3d6dc79"
dependencies:
css-parse "1.7.x"
debug "*"
glob "7.0.x"
mkdirp "0.5.x"
sax "0.5.x"
source-map "0.1.x"

wrappy@1:
version "1.0.2"
resolved "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"

0 comments on commit cf0ee58

Please sign in to comment.