Skip to content

Commit 7467ec7

Browse files
committed
use vue cli 3
1 parent bbf4f4d commit 7467ec7

File tree

20 files changed

+279
-11014
lines changed

20 files changed

+279
-11014
lines changed

README.md

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,46 @@
11
# vue-cli-plugin-component-lib
22

3-
## Project setup
4-
```
5-
npm install
6-
```
3+
create a component lib with example for `@vue/cli` 3.0.
74

8-
### Compiles and hot-reloads for development
9-
```
10-
npm run serve
11-
```
5+
## Feature
126

13-
### Compiles and minifies for production
14-
```
15-
npm run build
16-
```
7+
* example code for your component.
8+
* travis config if you need.
179

18-
### Run your tests
19-
```
20-
npm run test
21-
```
10+
## Install
2211

23-
### Lints and fixes files
24-
```
25-
npm run lint
12+
First you need to install `@vue/cli` globally (follow the instructions [here](https://cli.vuejs.org/)).
13+
14+
Then create a project and add the Element plugin:
15+
16+
```bash
17+
vue create my-app
18+
cd my-app
19+
vue add component-lib
2620
```
2721

28-
### Customize configuration
29-
See [Configuration Reference](https://cli.vuejs.org/config/).
22+
### Use with vue-cli UI
23+
24+
Skip this part if you've done everything in the `Install` section.
25+
26+
If you prefer managing your project in vue-cli UI (by running `vue ui`), here's how you can add component lib plugin: go to the Plugins menu, click the upper right `+ Add plugin` button, find `vue-cli-plugin-component-lib` and install it.
27+
28+
## Options
29+
30+
### travis
31+
32+
create ```.travis.yml``` for you project.
33+
34+
#### npm
35+
36+
depoly to npm by travis. and you may provide your email for you npm acount.
37+
38+
tips: you may config your travis env ```NPM_TOKEN``` first.
39+
40+
![npm token](doc/npm_token.png)
41+
42+
## Hack in your component
43+
44+
```sh
45+
yarn serve
46+
```

babel.config.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

doc/npm_token.png

54.7 KB
Loading

example/assets/logo.png

-6.69 KB
Binary file not shown.

generator/index.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
const camelCase = require('lodash.camelcase')
2+
const upperFirst = require('lodash.upperfirst')
3+
const kebabCase = require('lodash.kebabcase')
4+
const endsWith = require('lodash.endswith')
5+
6+
module.exports = (api, opts, rootOptions) => {
7+
// delete files created by default.
8+
api.postProcessFiles(files => {
9+
for (const file in files) {
10+
if (/src\/main\.js$|src\/App\.vue$|src\/components\/HelloWorld\.vue$/.test(file)) {
11+
delete files[file]
12+
}
13+
}
14+
})
15+
16+
const libNameCamelCase = upperFirst(camelCase(opts.libName))
17+
const libNameKebabCase = kebabCase(opts.libName)
18+
19+
api.extendPackage({
20+
name: libNameKebabCase,
21+
main: `dist/${opts.libName}.umd.min.js`,
22+
scripts: {
23+
'serve': 'vue-cli-service serve ./example/main.js',
24+
'build:lib': 'vue-cli-service build --target lib ./src/index.js',
25+
'build:example': 'vue-cli-service build --dest example/dist ./example/main.js',
26+
'build': 'npm run build:lib && npm run build:example',
27+
'lint': 'vue-cli-service lint'
28+
}
29+
})
30+
31+
if (opts.npm) {
32+
let repository = opts.repository
33+
if (endsWith(repository, '.git')) {
34+
repository = repository.substring(0, repository.length - 4)
35+
}
36+
api.extendPackage({
37+
private: false,
38+
description: opts.description,
39+
author: opts.author,
40+
license: opts.license,
41+
repository: {
42+
type: 'git',
43+
url: `git+${repository}.git`
44+
},
45+
bugs: {
46+
url: `${repository}issues`
47+
},
48+
homepage: repository,
49+
})
50+
}
51+
52+
api.render({
53+
'./example/components/ComponentLib.vue': './templates/example/components/ComponentLib.vue',
54+
'./example/App.vue': './templates/example/App.vue',
55+
'./example/main.js': './templates/example/main.js',
56+
}, {
57+
libNameCamelCase: libNameCamelCase
58+
})
59+
60+
api.render({
61+
'./src/index.js': './templates/src/index.js',
62+
'./src/my-component.vue': `./templates/src/${opts.libName}.vue`,
63+
}, {
64+
libNameCamelCase: libNameCamelCase
65+
})
66+
67+
if (opts.travis) {
68+
api.render({
69+
'./.travis.yml': './templates/_travis.yml'
70+
})
71+
}
72+
}

generator/templates/_travis.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
language: node_js
2+
node_js:
3+
- "10"
4+
script:
5+
- yarn build
6+
7+
<%_ if (options.npm) { _%>
8+
deploy:
9+
provider: npm
10+
email: <%= options.email %>
11+
api_key: "$NPM_TOKEN"
12+
skip_cleanup: true
13+
on:
14+
tags: true
15+
<%_ } _%>

example/App.vue renamed to generator/templates/example/App.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<template>
22
<div id="app">
3-
<img alt="Vue logo" src="./assets/logo.png">
4-
<component-lib/>
3+
<component-lib />
54
</div>
65
</template>
76

example/components/ComponentLib.vue renamed to generator/templates/example/components/ComponentLib.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
</template>
77

88
<script>
9-
import MyComponent from '../../src'
9+
import <%= libNameCamelCase %> from '../../src'
1010
export default {
1111
components: {
12-
MyComponent
12+
<%= libNameCamelCase %>
1313
},
14-
data () {
14+
data() {
1515
return {}
1616
}
1717
}
File renamed without changes.

generator/templates/src/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import <%= libNameCamelCase %> from './<%= options.libName %>'
2+
3+
const install = function (Vue) {
4+
Vue.component(<%= libNameCamelCase %>.name, <%= libNameCamelCase %>)
5+
}
6+
7+
/* istanbul ignore if */
8+
if (typeof window !== 'undefined' && window.Vue) {
9+
install(window.Vue)
10+
}
11+
12+
<%= libNameCamelCase %>.install = install
13+
export default <%= libNameCamelCase %>

src/my-component.vue renamed to generator/templates/src/my-component.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
<script>
66
export default {
7-
name: "my-component",
8-
data () {
7+
name: '<%= options.libName %>',
8+
data() {
99
return {}
1010
}
1111
};

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = () => {}

logo.png

2.22 KB
Loading

0 commit comments

Comments
 (0)