Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit 53bef66

Browse files
quimarcheznck
authored andcommitted
Support for stylus in <style> (#79)
1 parent 76d3022 commit 53bef66

File tree

11 files changed

+82
-24
lines changed

11 files changed

+82
-24
lines changed

config/build.js

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ rollup.rollup({
4343
'posthtml-attrs-parser',
4444
'pug',
4545
'rollup-pluginutils',
46+
'stylus',
4647
'vue-template-es2015-compiler',
4748
'vue-template-validator',
4849
].indexOf(id) > -1

docs/en/2.3/README.md

+27-21
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ npm install --save-dev rollup-plugin-vue
1616
yarn add --dev rollup-plugin-vue
1717
```
1818

19-
##### Use plugin
19+
##### Use plugin
2020
Next add `rollup-plugin-vue` to `rollup` plugins.
2121

2222
``` js
@@ -33,7 +33,7 @@ export default {
3333
For most cases `rollup-plugin-vue` works out of the box. But, you can always configure it to your needs.
3434

3535
### Style
36-
This section lists config options for `<style>` elements.
36+
This section lists config options for `<style>` elements.
3737

3838
#### Custom handler
3939
The `css` option accepts style handling options.
@@ -53,13 +53,13 @@ The `css` option accepts style handling options.
5353
- `$compiled: { code: String, ?map: Object }` - If [auto styles](#auto-styles) is enabled, `<style>` is transformed to `css`.
5454
- `compile: Function` - An async compiler that takes two parameters:
5555
- `style: { code: String, lang: String, ?map: Object }` - Style code and language.
56-
- `options: { ?sass: Object, ?less: Object, ?cssModules: Object }` - Processing library configuration options.
57-
56+
- `options: { ?sass: Object, ?less: Object, ?stylus: Object, ?cssModules: Object }` - Processing library configuration options.
57+
5858
``` js
5959
// rollup.config.js
6060
import fs from 'fs'
6161
import vue from 'rollup-plugin-vue'
62-
62+
6363
export default {
6464
...
6565
plugins: [
@@ -83,7 +83,7 @@ List of supported style languages:
8383

8484
- ##### CSS
8585
The default style language.
86-
86+
8787
- ##### Sass/Scss
8888
It uses `node-sass@^4.5.0` to process `sass/scss` style elements. You can provide `node-sass` configuration options by setting:
8989
``` js
@@ -96,10 +96,16 @@ It uses `less@^2.7.2` to process `less` style elements. You can provide `less` c
9696
less: { /* node-sass options */}
9797
```
9898

99+
- ##### Stylus
100+
It uses `stylus@^0.54.5` to process `stylus` style elements. You can provide `stylus` configuration options by setting:
101+
``` js
102+
stylus: { /* stylus options */}
103+
```
104+
99105
<p class="tip" markdown="1">
100-
`node-sass` and `less` are optional dependencies. If you are using `scss/sass/less` you should require (`yarn add --dev node-sass less`) them.
106+
`node-sass`, `less` and `stylus` are optional dependencies. If you are using `scss/sass/less/stylus` you should require (`yarn add --dev node-sass less stylus`) them.
101107
</p>
102-
108+
103109
#### Use other plugins
104110
Set `autoStyles: false` and `styleToImport: true` to import style as a dependency and plugins like [rollup-plugin-scss](https://github.com/differui/rollup-plugin-sass) can be used.
105111

@@ -137,7 +143,7 @@ export default {
137143
<p :class="{ [$style.red]: isRed }">
138144
Am I red?
139145
</p>
140-
146+
141147
<p :class="[$style.red, $style.bold]">
142148
Red and bold
143149
</p>
@@ -147,11 +153,11 @@ export default {
147153
<script>
148154
export default {
149155
computed: {
150-
156+
151157
$style () {
152158
return this.$options.cssModules
153159
}
154-
160+
155161
}
156162
}
157163
</script>
@@ -185,7 +191,7 @@ You can have more than one `<style>` tags in a single *.vue component. To avoid
185191
You can provide `postcss-modules` configuration options by setting:
186192
``` js
187193
cssModules: { generateScopedName: '[name]__[local]', ... }
188-
```
194+
```
189195

190196
### Template
191197
Templates are processed into `render` function by default. You can disable this by setting:
@@ -201,19 +207,19 @@ compileOptions: {
201207
```
202208

203209
#### Static Class Replacement
204-
When using CSS modules, class names are replaced in template at compile time.
210+
When using CSS modules, class names are replaced in template at compile time.
205211

206-
For example:
212+
For example:
207213
```
208214
<div class="red">Foo</div>
209-
```
210-
would become
215+
```
216+
would become
211217
```
212218
<div class="_lkcjalei8942jksa_0">Foo</div>
213-
```
219+
```
214220
before compiling to `render` function. This saves you from binding `class` attribute to `$style.red`.
215-
216-
You can disable this behavior by setting:
221+
222+
You can disable this behavior by setting:
217223
``` js
218224
disableCssModuleStaticReplacement: true
219225
```
@@ -224,7 +230,7 @@ disableCssModuleStaticReplacement: true
224230
Default template language.
225231

226232
- ##### Pug/Jade
227-
It uses `pug@^2.0.0-beta11` to process `pug` template elements. You can provide `pug` configuration options by setting:
233+
It uses `pug@^2.0.0-beta11` to process `pug` template elements. You can provide `pug` configuration options by setting:
228234
``` js
229235
pug: { /* pug options */}
230236
```
@@ -240,7 +246,7 @@ It uses `coffeescript-compiler@^0.1.1` to process `coffee` script elements. You
240246
### Handle with(this) issue
241247
Vue uses `with(this)` in render function as scoping rules of `with` aligns with scoping rules of templates. Using `with` in strict mode is forbidden.
242248

243-
`rollup-plugin-vue` strips away all `with(this)` statements by default. You can disable this by setting:
249+
`rollup-plugin-vue` strips away all `with(this)` statements by default. You can disable this by setting:
244250
``` js
245251
vue: { transforms: { stripWith: false } }
246252
```

src/options.js

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ export default {
5959
// Config for node-sass.
6060
scss: {},
6161

62+
// Config for stylus.
63+
stylus: {},
64+
6265
// Config for pug compiler.
6366
pug: {},
6467

src/style/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import { dirname, isAbsolute, resolve as resolvePath } from 'path'
33
import compileCSS from './css'
44
import compileSCSS from './scss'
55
import compileLESS from './less'
6+
import compileSTYLUS from './stylus'
67

78
const compilers = {
89
scss: compileSCSS,
910
sass: compileSCSS,
10-
less: compileLESS
11+
less: compileLESS,
12+
stylus: compileSTYLUS
1113
}
1214

1315
export async function compile (style, options) {

src/style/stylus.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import stylus from 'stylus'
2+
3+
export default async function (style, options) {
4+
const stylusObj = stylus(style.code, {...options.stylus})
5+
.set('filename', style.id)
6+
.set('sourcemap', {
7+
'comment': false
8+
})
9+
10+
const code = await stylusObj.render()
11+
const map = stylusObj.sourcemap
12+
13+
style.$compiled = {
14+
code,
15+
map
16+
}
17+
18+
return style
19+
}

test/expects/no-css-extract.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(function(){ if(document){ var head=document.head||document.getElementsByTagName('head')[0], style=document.createElement('style'), css=" .bar { color: blue } .foo { color: red; } "; style.type='text/css'; if (style.styleSheet){ style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); } head.appendChild(style); } })();
1+
(function(){ if(document){ var head=document.head||document.getElementsByTagName('head')[0], style=document.createElement('style'), css=".baz { color: #008000; } .bar { color: blue } .foo { color: red; } "; style.type='text/css'; if (style.styleSheet){ style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); } head.appendChild(style); } })();
22

33

44

test/expects/stylus.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.stylus__test {
2+
color: #f00;
3+
}

test/expects/stylus.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var stylus = { template: "<div class=\"stylus__test\"></div>",cssModules: {"test":"stylus__test"},};
2+
3+
export default stylus;

test/fixtures/no-css-extract.vue

+7
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,10 @@ $red: red;
1919
color: blue
2020
}
2121
</style>
22+
23+
<style lang="stylus">
24+
$green = green
25+
26+
.baz
27+
color $green
28+
</style>

test/fixtures/stylus.vue

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<template>
2+
<div class="test"></div>
3+
</template>
4+
5+
<script lang="babel">
6+
export default {}
7+
</script>
8+
9+
<style lang="stylus" module>
10+
$var = red
11+
12+
.test
13+
color $var
14+
</style>

test/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function test(name) {
4141
assert.equal(code.trim(), expected.trim(), 'should compile code correctly')
4242

4343
// Check css output
44-
if (['style', 'css-modules', 'css-modules-static', 'scss', 'pug', 'less'].indexOf(name) > -1) {
44+
if (['style', 'css-modules', 'css-modules-static', 'scss', 'pug', 'less', 'stylus'].indexOf(name) > -1) {
4545
var css = read('expects/' + name + '.css')
4646
assert.equal(css.trim(), actualCss.trim(), 'should output style tag content')
4747
} else if (['no-css-extract'].indexOf(name) > -1) {

0 commit comments

Comments
 (0)