Skip to content

Commit e110aa0

Browse files
committed
feat: use @vue/component-compiler
1 parent 31a8c57 commit e110aa0

File tree

138 files changed

+12885
-3943
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+12885
-3943
lines changed

README.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ As vue-loader is for webpack and vueify is for browserify, similarly its for rol
77

88
With rollup you can break your application into reusable modules.
99

10-
> See [docs](http://vuejs.github.io/rollup-plugin-vue) for installing, using and contributing.
11-
1210
<p align="center">
1311
<a href="https://circleci.com/gh/vuejs/rollup-plugin-vue">
1412
<img src="https://circleci.com/gh/vuejs/rollup-plugin-vue.svg?style=svg" alt="Build Status" />
@@ -37,6 +35,19 @@ With rollup you can break your application into reusable modules.
3735
</a>
3836
</p>
3937

38+
## Usage
39+
40+
```js
41+
import vue from 'rollup-plugin-vue'
42+
43+
export default {
44+
entry: 'main.js',
45+
plugins: [
46+
vue(/* options */)
47+
]
48+
}
49+
```
50+
4051
## Security
4152

4253
If you discover any security related issues, please email [email protected] instead of using the issue tracker.

config/banner.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
"use strict";
1+
'use strict'
22

3-
let pack = require('../package.json');
3+
const pack = require('../package.json')
44

5-
const VERSION = process.env.VERSION || pack.version;
6-
const YEAR = new Date().getFullYear();
5+
const VERSION = process.env.VERSION || pack.version
6+
const YEAR = new Date().getFullYear()
77

88
const BANNER = `/*!
99
* ${pack.name} v${VERSION}
1010
* (c) ${YEAR} ${pack.author}
1111
* Release under the ${pack.license} License.
12-
*/`;
12+
*/`
1313

14-
module.exports = BANNER;
14+
module.exports = BANNER

config/build.js

+35-53
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,47 @@
22

33
const babel = require('rollup-plugin-babel')
44
const rollup = require('rollup')
5-
const replace = require('rollup-plugin-replace')
6-
const zlib = require('zlib')
7-
const fs = require('fs')
85
const pack = require('../package.json')
9-
const banner = require('./banner')
106

11-
const main = fs
12-
.readFileSync('src/index.js', 'utf-8')
13-
.replace(/plugin\.version = '[\d\.]+'/, `plugin.version = '${pack.version}'`)
7+
const dependencies = Object.keys(pack.dependencies).concat('path')
148

15-
fs.writeFileSync('src/index.js', main)
16-
17-
rollup.rollup({
9+
rollup
10+
.rollup({
1811
input: 'src/index.js',
12+
external(id) {
13+
return dependencies.some(it => it === id || id.startsWith(it))
14+
},
1915
plugins: [
20-
babel({ runtimeHelpers: true })
21-
],
22-
external (id) {
23-
if (/babel-runtime\/.*/i.test(id)) {
24-
return true
25-
}
26-
27-
return [
28-
'camelcase',
29-
'coffeescript-compiler',
30-
'de-indent',
31-
'debug',
32-
'fs',
33-
'hash-sum',
34-
'html-minifier',
35-
'less',
36-
'magic-string',
37-
'merge-options',
38-
'node-sass',
39-
'parse5',
40-
'path',
41-
'postcss',
42-
'postcss-load-config',
43-
'postcss-modules',
44-
'postcss-selector-parser',
45-
'posthtml',
46-
'posthtml-attrs-parser',
47-
'pug',
48-
'rollup-pluginutils',
49-
'stylus',
50-
'vue-template-es2015-compiler',
51-
'vue-template-validator',
52-
'typescript'
53-
].indexOf(id) > -1
54-
}
55-
}).then(function (bundle) {
16+
babel({
17+
exclude: 'node_modules/**',
18+
babelrc: false,
19+
presets: [
20+
[
21+
'@babel/preset-env',
22+
{
23+
modules: false,
24+
target: { node: 6 }
25+
}
26+
]
27+
],
28+
plugins: [
29+
'@babel/plugin-proposal-object-rest-spread',
30+
'@babel/plugin-transform-runtime'
31+
],
32+
runtimeHelpers: true
33+
})
34+
]
35+
})
36+
.then(bundle => {
5637
bundle.write({
57-
format: 'cjs',
58-
file: 'dist/' + pack.name + '.common.js'
38+
format: 'cjs',
39+
file: 'dist/' + pack.name + '.common.js',
40+
sourcemap: true
5941
})
6042
bundle.write({
61-
format: 'es',
62-
file: 'dist/' + pack.name + '.js'
43+
format: 'es',
44+
file: 'dist/' + pack.name + '.js',
45+
sourcemap: true
6346
})
64-
}).catch(function logError (e) {
65-
console.log(e)
66-
})
47+
})
48+
.catch(console.error)

docs/config.js

+43-36
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,58 @@
11
const languages = {
2-
title: 'Language',
3-
type: 'dropdown',
4-
exact: true,
5-
items: [
6-
{ title: 'English', path: '/en/', matchPath: /\/en\/.*/i }
7-
]
2+
title: 'Language',
3+
type: 'dropdown',
4+
exact: true,
5+
items: [{ title: 'English', path: '/en/', matchPath: /\/en\/.*/i }]
86
}
97

108
const home = { title: 'Home', path: '/' }
119

1210
const versions = [
13-
{ title: 'Version 2.2', path: '/2.2/', matchPath: /^\/([a-z-]+)\/2.2\/.*/i },
14-
{ title: 'Version 2.3', path: '/2.3/', matchPath: /^\/([a-z-]+)\/2.3\/.*/i },
11+
{ title: 'Version 2.2', path: '/2.2/', matchPath: /^\/([a-z-]+)\/2.2\/.*/i },
12+
{ title: 'Version 2.3', path: '/2.3/', matchPath: /^\/([a-z-]+)\/2.3\/.*/i }
1513
]
1614

1715
function lang_version(lang) {
18-
const version = {
19-
title: 'Version',
20-
type: 'dropdown',
21-
exact: true,
22-
}
23-
version.items = versions.map(function (v) {
24-
const ver = Object.assign({}, v)
25-
ver.path = '/' + lang + ver.path
26-
27-
return ver
28-
})
16+
const version = {
17+
title: 'Version',
18+
type: 'dropdown',
19+
exact: true
20+
}
21+
version.items = versions.map(function(v) {
22+
const ver = Object.assign({}, v)
23+
ver.path = '/' + lang + ver.path
2924

30-
return version
25+
return ver
26+
})
27+
28+
return version
3129
}
3230

3331
docute.init({
34-
repo: 'vuejs/rollup-plugin-vue',
35-
'edit-link': 'https://github.com/vuejs/rollup-plugin-vue/edit/master/docs',
36-
37-
nav: {
38-
default: [home, languages, lang_version('en')],
39-
'en2.3': [{ title: 'Home', path: '/en/2.3/' }, { title: 'Examples', path: '/en/2.3/examples' }, languages, lang_version('en')],
40-
'en2.2': [{ title: 'Home', path: '/en/2.2/' }, { title: 'Examples', path: '/en/2.2/examples' }, languages, lang_version('en')],
41-
},
42-
43-
plugins: [
44-
docsearch({
45-
apiKey: '7792597613e997afeb0b75a206ca0c5a',
46-
indexName: 'rollup-plugin-vue',
47-
url: 'https://vuejs.github.io/rollup-plugin-vue'
48-
})
32+
repo: 'vuejs/rollup-plugin-vue',
33+
'edit-link': 'https://github.com/vuejs/rollup-plugin-vue/edit/master/docs',
34+
35+
nav: {
36+
default: [home, languages, lang_version('en')],
37+
'en2.3': [
38+
{ title: 'Home', path: '/en/2.3/' },
39+
{ title: 'Examples', path: '/en/2.3/examples' },
40+
languages,
41+
lang_version('en')
42+
],
43+
'en2.2': [
44+
{ title: 'Home', path: '/en/2.2/' },
45+
{ title: 'Examples', path: '/en/2.2/examples' },
46+
languages,
47+
lang_version('en')
4948
]
50-
49+
},
50+
51+
plugins: [
52+
docsearch({
53+
apiKey: '7792597613e997afeb0b75a206ca0c5a',
54+
indexName: 'rollup-plugin-vue',
55+
url: 'https://vuejs.github.io/rollup-plugin-vue'
56+
})
57+
]
5158
})

example/Hello.vue

+6-13
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1-
<template>
2-
<div class="hello">
3-
<h1 class="hello__title">{{ msg }}</h1>
4-
</div>
1+
<template functional>
2+
<div class="hello">{{ props.message }}</div>
53
</template>
64

75
<script>
86
export default {
9-
data () {
10-
return {
11-
msg: 'Hello World!'
12-
}
13-
}
7+
props: ['message']
148
}
159
</script>
1610

17-
<style lang="stylus">
11+
12+
<style scoped>
1813
.hello {
19-
&__title {
20-
color: #42b983;
21-
}
14+
color: red;
2215
}
2316
</style>

example/build.js

+10-24
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,21 @@ const CleanCSS = require('clean-css')
66
const fs = require('fs')
77
const stylus = require('stylus')
88

9-
109
rollup({
1110
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-
]
11+
plugins: [vue(), buble()]
2612
})
27-
.then(function (bundle) {
13+
.then(function(bundle) {
2814
var code = bundle.generate({
2915
format: 'umd',
3016
moduleName: 'helloRollupVue',
3117
useStrict: false
3218
}).code
33-
return write('dist/papervue.js', code).then(function () {
19+
return write('dist/papervue.js', code).then(function() {
3420
return code
3521
})
3622
})
37-
.then(function (code) {
23+
.then(function(code) {
3824
var minified = uglify.minify(code, {
3925
fromString: true,
4026
output: {
@@ -45,24 +31,24 @@ rollup({
4531
})
4632
.catch(logError)
4733

48-
function write (dest, code) {
49-
return new Promise(function (resolve, reject) {
50-
fs.writeFile(dest, code, function (err) {
34+
function write(dest, code) {
35+
return new Promise(function(resolve, reject) {
36+
fs.writeFile(dest, code, function(err) {
5137
if (err) return reject(err)
5238
console.log(blue(dest) + ' ' + getSize(code))
5339
resolve()
5440
})
5541
})
5642
}
5743

58-
function getSize (code) {
44+
function getSize(code) {
5945
return (code.length / 1024).toFixed(2) + 'kb'
6046
}
6147

62-
function logError (e) {
48+
function logError(e) {
6349
console.log(e)
6450
}
6551

66-
function blue (str) {
52+
function blue(str) {
6753
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m'
6854
}

example/package.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"private": true,
3+
"devDependencies": {
4+
"rollup-plugin-closure-compiler-js": "^1.0.5",
5+
"rollup-plugin-commonjs": "^8.2.1",
6+
"rollup-plugin-node-resolve": "^3.0.0",
7+
"rollup-plugin-prepack": "^1.0.0",
8+
"vue-style-loader": "^3.0.3"
9+
},
10+
"dependencies": {
11+
"@vue/component-compiler-utils": "^1.2.1",
12+
"resolve": "^1.4.0",
13+
"rollup-plugin-buble": "^0.19.2",
14+
"vue-runtime-helpers": "^0.1.0"
15+
}
16+
}

example/rollup.config.js

+13-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
// Simple rollup config file.
22

3-
const vue = require('../dist/rollup-plugin-vue.common.js');
4-
const buble = require('rollup-plugin-buble');
3+
const vue = require('../dist/rollup-plugin-vue.common.js')
4+
const buble = require('rollup-plugin-buble')
5+
// const prepack = require('rollup-plugin-prepack')
6+
// const closure = require('rollup-plugin-closure-compiler-js')
7+
const node = require('rollup-plugin-node-resolve')
8+
// const commonjs = require('rollup-plugin-commonjs')
9+
10+
process.env.NODE_ENV = 'production'
511

612
export default {
7-
name: 'helloRollupVue',
8-
input: './index.js',
9-
output: {
10-
file: 'dist/bundle.js',
11-
format: 'umd'
12-
},
13-
plugins: [
14-
vue({
15-
compileTemplate: true,
16-
css: 'dist/bundle.css'
17-
}),
18-
buble()
19-
]
20-
};
13+
name: 'ff',
14+
input: 'index.js',
15+
format: 'es',
16+
plugins: [vue(), buble()]
17+
}

0 commit comments

Comments
 (0)