如何判断Vue项目基于vue-cli 2还是3创建?导入Vue路径异常排查
Hey there! Let's break down how to figure out which version of vue-cli was used to create your project—super straightforward checks, no guesswork needed:
Check your project root directory structure
- If you see
build/andconfig/folders (with webpack config files likewebpack.base.conf.jsinsidebuild/), plus astatic/folder for static assets, that's a dead giveaway for vue-cli 2. - If your project has a
public/folder instead ofstatic/, and nobuild/orconfig/folders (configuration lives in a singlevue.config.jsfile if you've customized it), then it's vue-cli 3 or later (vue-cli 3+ switched to a more streamlined structure).
- If you see
Look at your
package.jsonfile- For vue-cli 2: You'll see
vue-clilisted in your dependencies, and the scripts section will have something like"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js"for starting the dev server. - For vue-cli 3+: Your dependencies will include
@vue/cli-service, and the dev start script will be"serve": "vue-cli-service serve". You might also see various@vue/cli-plugin-*packages if you added features like Babel or ESLint during setup.
- For vue-cli 2: You'll see
Your Vue import quirk as a supporting clue
The fact that you need to useimport Vue from 'vue/dist/vue.js'instead of the standardimport Vue from 'vue'also leans towards vue-cli 2. By default, vue-cli 2 uses the runtime-only build of Vue (which doesn't include the template compiler), so you have to import the full build to use inline templates. Vue-cli 3+ defaults to including the compiler build, so you wouldn't need this workaround unless you explicitly changed the config.
Put it all together, and you should have a clear answer!
内容的提问来源于stack exchange,提问作者Philipp S.

