@@ -8,7 +8,7 @@ const babelPlugin = toPlugin('@vue/cli-plugin-babel')
8
8
const eslintPlugin = toPlugin ( '@vue/cli-plugin-eslint' )
9
9
const createConfigPlugin = require ( './lib/createConfigPlugin' )
10
10
11
- function createService ( entry ) {
11
+ function resolveEntry ( entry ) {
12
12
const context = process . cwd ( )
13
13
14
14
entry = entry || findExisting ( context , [
@@ -29,6 +29,13 @@ function createService (entry) {
29
29
process . exit ( 1 )
30
30
}
31
31
32
+ return {
33
+ context,
34
+ entry
35
+ }
36
+ }
37
+
38
+ function createService ( context , entry , asLib ) {
32
39
return new Service ( context , {
33
40
projectOptions : {
34
41
compiler : true ,
@@ -37,15 +44,21 @@ function createService (entry) {
37
44
plugins : [
38
45
babelPlugin ,
39
46
eslintPlugin ,
40
- createConfigPlugin ( context , entry )
47
+ createConfigPlugin ( context , entry , asLib )
41
48
]
42
49
} )
43
50
}
44
51
45
- exports . serve = ( entry , args ) => {
46
- createService ( entry ) . run ( 'serve' , args )
52
+ exports . serve = ( _entry , args ) => {
53
+ const { context, entry } = resolveEntry ( _entry )
54
+ createService ( context , entry ) . run ( 'serve' , args )
47
55
}
48
56
49
- exports . build = ( entry , args ) => {
50
- createService ( entry ) . run ( 'build' , args )
57
+ exports . build = ( _entry , args ) => {
58
+ const { context, entry } = resolveEntry ( _entry )
59
+ const asLib = args . target && args . target !== 'app'
60
+ if ( asLib ) {
61
+ args . libEntry = entry
62
+ }
63
+ createService ( context , entry , asLib ) . run ( 'build' , args )
51
64
}
0 commit comments