简体   繁体   English

为什么要在 Babel 和 ESLint 上使用 Vue CLI?

[英]Why use Vue CLI for Babel and ESLint?

I am just starting out with Node.js and Vue.js, and I noticed that Vue.js has a Vue CLI tooling kit (whatever that means) which gives you a scaffolding project (don't need it I think?) but it also adds ESLint and Babel.我刚开始使用 Node.js 和 Vue.js,我注意到 Vue.js 有一个 Vue CLI 工具包(不管这意味着什么),它为您提供了一个脚手架项目(我认为不需要它?)但它还添加了 ESLint 和 Babel。

The thing is, it adds them like this:问题是,它像这样添加它们:

"plugins": {
    "@vue/cli-plugin-babel": {},
    "@vue/cli-plugin-eslint": {
      "config": "airbnb",
      "lintOn": ["save", "commit"]
    }
}

What is the difference between Vue's Babel @vue/cli-plugin-babel and installing Babel using NPM? Vue 的 Babel @vue/cli-plugin-babel和使用 NPM 安装 Babel 有什么区别? Why do vue add cli-plugin-eslint instead of npm install eslint ?为什么vue add cli-plugin-eslint而不是npm install eslint

Most important difference is that Vue CLI (and it's plugins) doesn't just add tools to your project but also provide configuration for the tools added (webpack/babel/eslint etc.) with sensible defaults (while still allowing you to fine-tune it)最重要的区别是 Vue CLI(及其插件)不仅为您的项目添加工具,还为添加的工具(webpack/babel/eslint 等)提供合理的默认配置(同时仍允许您进行微调)它)

So you can spend more time developing your app instead of figuring out how to setup dev/prod build tool chain...所以你可以花更多的时间来开发你的应用程序,而不是弄清楚如何设置开发/生产构建工具链......

Tools like Babel and ESLint are configured to work with Vue but it doesn't mean they work only for Vue specific features (for example Vue single file components). Babel 和 ESLint 等工具配置为与 Vue 一起使用,但这并不意味着它们仅适用于 Vue 特定功能(例如 Vue 单文件组件)。 You can add pure JavaScript file into your project and Babel and ESLint will still work with it.你可以将纯 JavaScript 文件添加到你的项目中,Babel 和 ESLint 仍然可以使用它。

You can use some boilerplate or template for that but Vue CLI is better because it allows seamless updates to the tooling and configuration during whole project lifetime (instead of generating structure and config for you at the beginning and leave future updates to you).您可以为此使用一些boilerplate或模板,但 Vue CLI 更好,因为它允许在整个项目生命周期内对工具和配置进行无缝更新(而不是在开始时为您生成结构和配置,并将未来的更新留给您)。

For example lets say your project is using SASS in VUE single file components.例如,假设您的项目在 VUE 单文件组件中使用 SASS。 You need a sass-loader Webpack plugin for that.为此,您需要一个sass-loader Webpack 插件。 Then sass-loader maintainers decide they need to change structure of their configuration (as happened recently ).然后sass-loader维护者决定他们需要改变他们的配置结构( 最近发生的)。 If your project is based on the template of some kind, you can udpate to newer version of sass-loader but you'll also need to figure out what changes in configuration are needed to make it work again.如果您的项目基于某种模板,您可以更新到较新版本的sass-loader但您还需要弄清楚需要对配置进行哪些更改才能使其再次运行。 If you are using Vue CLI (and CLI team decides to update to newest version of sass-loader ), you just update Vue CLI (or it's plugin) and you good to go (because someone on Vue CLI team figured out what needs to be changed and done it)如果您正在使用 Vue CLI(并且 CLI 团队决定更新到最新版本的sass-loader ),您只需更新 Vue CLI(或它的插件)就可以了(因为 Vue CLI 团队中的某个人知道需要做什么)更改并完成了)

If you are just starting with Node/Vue, it's highly recommended to base your project on Vue CLI instead of trying to start from scratch....如果您刚开始使用 Node/Vue,强烈建议您将项目基于 Vue CLI,而不是尝试从头开始......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM