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

Commit 398aabe

Browse files
posvaznck
authored andcommitted
Add example (#19)
1 parent 6150187 commit 398aabe

File tree

6 files changed

+109
-0
lines changed

6 files changed

+109
-0
lines changed

example/Hello.vue

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<template>
2+
<div class="hello">
3+
<h1 class="hello__title">{{ msg }}</h1>
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
data () {
10+
return {
11+
msg: 'Hello World!'
12+
}
13+
}
14+
}
15+
</script>
16+
17+
<style lang="stylus">
18+
.hello {
19+
&__title {
20+
color: #42b983;
21+
}
22+
}
23+
</style>

example/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Simple example
2+
===
3+
4+
Example bundling an UMD package with one `vue` file and exporting stylus and CSS (both minified and unminified) to different files.
5+
6+
## Building
7+
8+
```
9+
cd example
10+
node build.js
11+
ls dist
12+
```

example/build.js

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const rollup = require('rollup').rollup
2+
const vue = require('../dist/rollup-plugin-vue.common.js')
3+
const buble = require('rollup-plugin-buble')
4+
const uglify = require('uglify-js')
5+
const CleanCSS = require('clean-css')
6+
const fs = require('fs')
7+
const stylus = require('stylus')
8+
9+
10+
rollup({
11+
entry: 'index.js',
12+
plugins: [
13+
vue({
14+
compileTemplate: true,
15+
css (styles, stylesNodes) {
16+
write('dist/papervue.styl', styles)
17+
stylus.render(styles, function (err, css) {
18+
if (err) throw err
19+
write('dist/papervue.css', css)
20+
write('dist/papervue.min.css', new CleanCSS().minify(css).styles)
21+
})
22+
}
23+
}),
24+
buble()
25+
]
26+
})
27+
.then(function (bundle) {
28+
var code = bundle.generate({
29+
format: 'umd',
30+
moduleName: 'helloRollupVue',
31+
useStrict: false
32+
}).code
33+
return write('dist/papervue.js', code).then(function () {
34+
return code
35+
})
36+
})
37+
.then(function (code) {
38+
var minified = uglify.minify(code, {
39+
fromString: true,
40+
output: {
41+
ascii_only: true
42+
}
43+
}).code
44+
return write('dist/papervue.min.js', minified)
45+
})
46+
.catch(logError)
47+
48+
function write (dest, code) {
49+
return new Promise(function (resolve, reject) {
50+
fs.writeFile(dest, code, function (err) {
51+
if (err) return reject(err)
52+
console.log(blue(dest) + ' ' + getSize(code))
53+
resolve()
54+
})
55+
})
56+
}
57+
58+
function getSize (code) {
59+
return (code.length / 1024).toFixed(2) + 'kb'
60+
}
61+
62+
function logError (e) {
63+
console.log(e)
64+
}
65+
66+
function blue (str) {
67+
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m'
68+
}

example/dist/.gitkeep

Whitespace-only changes.

example/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Hello from './Hello.vue'
2+
3+
export default Hello

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
},
4040
"devDependencies": {
4141
"babel-eslint": "^6.1.2",
42+
"clean-css": "^3.4.19",
4243
"coveralls": "^2.11.6",
4344
"eslint": "^3.3.1",
4445
"eslint-config-airbnb": "^10.0.1",
@@ -53,6 +54,8 @@
5354
"rollup": "latest",
5455
"rollup-plugin-buble": "^0.13.0",
5556
"rollup-plugin-replace": "latest",
57+
"stylus": "^0.54.5",
58+
"uglify-js": "^2.7.3",
5659
"vue-hot-reload-api": "^1.2.2"
5760
}
5861
}

0 commit comments

Comments
 (0)