vuejs / vue-cli

🛠️ webpack-based tooling for Vue.js Development
https://cli.vuejs.org/
MIT License
29.75k stars 6.33k forks source link

Improve vue build help (facing a "Failed to locate entry file" error) #2473

Closed cmermingas closed 5 years ago

cmermingas commented 6 years ago

What problem does this feature solve?

After creating a project with the cli, I cd into the project folder and run vue build, only to get a Failed to locate entry file error. When I try run vue build --help, I get this:

$ vue build --help

  Usage: build [options] [entry]

  build a .js or .vue file in production mode with zero config

  Options:

    -t, --target <target>  Build target (app | lib | wc | wc-async, default: app)
    -n, --name <name>      name for lib or web-component mode (default: entry filename)
    -d, --dest <dir>       output directory (default: dist)
    -h, --help             output usage information

That optional entry argument is not document. Since it's optional, I was not providing. Turns out that running vue build ./src/main.js works.

What does the proposed API look like?

It would be great if the use of the optional entry argument was explained in the cli help or if the cli could automatically figure it out, perhaps by reading the entry from the cli-controlled webpack config:

  entry: {
    app: [
      './src/main.js'
    ]
  }
LinusBorg commented 6 years ago

I'm not quite sure I can follow.

Did you or did you not use the --target flag?

You talk about it as if you did, yet nowhere in your snippets did you use it. Would be thankful iuf you could clarify what command you precisely ran when it failed vs. when it worked.

cmermingas commented 6 years ago

The entry argument, not target. It’s shown in brackets, which leads me to believe that it’s optional.

It failed when I ran “vue build”. It worked when I ran “vue build ./src/main.js”

LinusBorg commented 6 years ago

Well it is optional, and /src/main.js is the default, which is why I was confused.

If that doesn't work for you, please provide a repository with a project that reproduces your issue.

cmermingas commented 6 years ago

Sure. It's just after running vue create hello-world. I pushed it here: https://github.com/cmermingas/vue-hello-world

Edit: I deleted this repo

haoqunjiang commented 6 years ago

Well, you should run npm run build rather than vue build.

They are two different commands.

cmermingas commented 6 years ago

@sodatea - My only request on this issue is to improve the CLI help. If the help said what you typed in the second bullet in your comment above, it would have been clear from the beginning and I wouldn't have been motivated to open this ticket. Instead, the help says build a .js or .vue file in production mode with zero config, which is misleading because:

LinusBorg commented 6 years ago

While I think we can indeed improve this, I'm not sure all of your points are valid. We don't aim to replicate all of the extensive documentation that we provide on https://cli.vuejs.org.

Sure, the CLI help should be able to give correct, instant pointers about what each option does, but that does not free the developer from reading the documentation to learn how to use a tool correctly in all circumstances.

It says production, which contradicts your statement about instant prototyping only.

Well, the term mode has a special meaning in the context of vue-cli, see here, and it certainly does not mean "production-ready application"

So in the context, I think this phrase is absolutely correct:

It doesn't mention that the file used must be given in the entry argument.

Because you don't have to provide the argument if you use any of the default values. Or do you mean that the term entry is not defined to mean "file which starts the application/prototype"? I think the term is suffiently established to mean exactly that. If people are unclear what it means, they can refer to the documentation.

It doesn't indicate what this optional entry argument defaults to.

We should document these defaults in the cli help, no argument here

Worthaboutapig commented 6 years ago

I think the use of the term entry was inadvisable, as I had assumed it to be a webpack entry and it isn't. I think it would be helpful if the documentation clarified that the vue-cli lib [entry] is not a webpack entry, but simple a file path to the 'root' file to build the library export.

It took me a while to get it working, as I had kind of assumed that it was a webpack entry and it took a few readings of the docs to realise it referred to a file. One could argue that reading the documents properly would help, but the reality is that people skim read these things and so I feel a short bracketed note or similar would be helpful.

smilingkite commented 5 years ago

I do think that it is a bit difficult on newbies (just the kind of people who use vue cli without knowing webpack very well) to expect them to realize that they should just use 'npm run build' instead of all the options mentioned in the guide.