@@ -8,9 +8,36 @@ const babelPlugin = toPlugin('@vue/cli-plugin-babel')
88const eslintPlugin = toPlugin ( '@vue/cli-plugin-eslint' )
99const globalConfigPlugin = require ( './lib/globalConfigPlugin' )
1010
11- function resolveEntry ( entry ) {
12- const context = process . cwd ( )
11+ const context = process . cwd ( )
1312
13+ function warnAboutNpmScript ( cmd ) {
14+ const packageJsonPath = path . join ( context , 'package.json' )
15+
16+ if ( ! fs . existsSync ( packageJsonPath ) ) {
17+ return
18+ }
19+
20+ let pkg
21+ try {
22+ pkg = require ( packageJsonPath )
23+ } catch ( e ) {
24+ return
25+ }
26+
27+ if ( ! pkg . scripts || ! pkg . scripts [ cmd ] ) {
28+ return
29+ }
30+
31+ let script = `npm run ${ cmd } `
32+ if ( fs . existsSync ( path . join ( context , 'yarn.lock' ) ) ) {
33+ script = `yarn ${ cmd } `
34+ }
35+
36+ console . log ( `There's a ${ chalk . yellow ( 'package.json' ) } in the current directory.` )
37+ console . log ( `Did you mean ${ chalk . yellow ( script ) } ?` )
38+ }
39+
40+ function resolveEntry ( entry , cmd ) {
1441 entry = entry || findExisting ( context , [
1542 'main.js' ,
1643 'index.js' ,
@@ -21,14 +48,21 @@ function resolveEntry (entry) {
2148 if ( ! entry ) {
2249 console . log ( chalk . red ( `Failed to locate entry file in ${ chalk . yellow ( context ) } .` ) )
2350 console . log ( chalk . red ( `Valid entry file should be one of: main.js, index.js, App.vue or app.vue.` ) )
51+
52+ console . log ( )
53+ warnAboutNpmScript ( cmd )
2454 process . exit ( 1 )
2555 }
2656
2757 if ( ! fs . existsSync ( path . join ( context , entry ) ) ) {
2858 console . log ( chalk . red ( `Entry file ${ chalk . yellow ( entry ) } does not exist.` ) )
59+
60+ console . log ( )
61+ warnAboutNpmScript ( cmd )
2962 process . exit ( 1 )
3063 }
3164
65+ warnAboutNpmScript ( cmd )
3266 return {
3367 context,
3468 entry
@@ -50,12 +84,12 @@ function createService (context, entry, asLib) {
5084}
5185
5286exports . serve = ( _entry , args ) => {
53- const { context, entry } = resolveEntry ( _entry )
87+ const { context, entry } = resolveEntry ( _entry , 'serve' )
5488 createService ( context , entry ) . run ( 'serve' , args )
5589}
5690
5791exports . build = ( _entry , args ) => {
58- const { context, entry } = resolveEntry ( _entry )
92+ const { context, entry } = resolveEntry ( _entry , 'build' )
5993 const asLib = args . target && args . target !== 'app'
6094 if ( asLib ) {
6195 args . entry = entry
0 commit comments