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

Commit b503965

Browse files
committed
fix #233, Update cookbook library example
1 parent 2ae1bbf commit b503965

File tree

5 files changed

+37
-11
lines changed

5 files changed

+37
-11
lines changed

cookbook/library/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"scripts": {
44
"build": "rollup -c --environment BUILD:production"
55
},
6-
"main": "./dist/MyComponent.ssr.js",
7-
"module": "./dist/MyComponent.esm.js",
8-
"browser": "./dist/MyComponent.js",
9-
"unpkg": "./dist/MyComponent.js",
6+
"main": "./dist/library.ssr.js",
7+
"module": "./dist/library.esm.js",
8+
"browser": "./dist/library.js",
9+
"unpkg": "./dist/library.js",
1010
"devDependencies": {
1111
"rollup": "^0.59.4",
1212
"rollup-plugin-css-only": "^0.4.0",

cookbook/library/rollup.config.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ import vue from 'rollup-plugin-vue'
33
export default [
44
// ESM build to be used with webpack/rollup.
55
{
6-
input: 'src/MyComponent.vue',
6+
input: 'src/index.js',
77
output: {
88
format: 'esm',
9-
file: 'dist/MyComponent.esm.js'
9+
file: 'dist/library.esm.js'
1010
},
1111
plugins: [
1212
vue()
1313
]
1414
},
1515
// SSR build.
1616
{
17-
input: 'src/MyComponent.vue',
17+
input: 'src/index.js',
1818
output: {
1919
format: 'cjs',
20-
file: 'dist/MyComponent.ssr.js'
20+
file: 'dist/library.ssr.js'
2121
},
2222
plugins: [
2323
vue({ template: { optimizeSSR: true } })
@@ -28,7 +28,7 @@ export default [
2828
input: 'src/wrapper.js',
2929
output: {
3030
format: 'iife',
31-
file: 'dist/MyComponent.js'
31+
file: 'dist/library.js'
3232
},
3333
plugins: [
3434
vue()
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<template>
2+
<h1>Hello {{ name }}</h1>
3+
</template>
4+
5+
<script>
6+
export default {
7+
data() {
8+
return { name: 'Jane Doe' }
9+
}
10+
}
11+
</script>
12+
13+
<style scoped>
14+
h1 {
15+
color: red;
16+
}
17+
</style>

cookbook/library/src/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import MyComponent from './MyComponent.vue'
2+
import OtherComponent from './OtherComponent.vue'
3+
4+
export {
5+
MyComponent,
6+
OtherComponent
7+
}

cookbook/library/src/wrapper.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import MyComponent from './MyComponent.vue'
1+
import * as components from './index'
22

33
if (typeof Vue !== 'undefined') {
4-
Vue.component('MyComponent', MyComponent)
4+
for (const name in components) {
5+
Vue.component(name, components[name])
6+
}
57
}

0 commit comments

Comments
 (0)