官术网_书友最值得收藏!

Vue CLI

The Vue Command Line Interface (CLI) allows us to quickly scaffold new Vue projects with a variety of different template options. Currently, the template options available include technologies such as Webpack, Browserify, and Progressive Web Application features.

Sure, we could create our own Vue application and manually add tools such as Webpack, but this creates technical overhead in the sense that we have to learn, build, and maintain our configuration. The Vue CLI does this for us while maintaining a select set of official templates, but doesn't restrict us from modifying the generated Webpack configuration. All of this allows us to generate new unopinionated Vue projects.

To start using the Vue CLI, let's ensure we have it installed:

npm install vue-cli -g

We can then use the Vue init command to scaffold a new Vue project using the Webpack template:

vue init webpack-simple my-vue-project

On entering the preceding command we should get the following as shown on the Terminal:

Creating projects with Vue init

If we break this down, we're essentially initializing a new Vue project based on the webpack-simple template named my-vue-project. We're then navigated to a wizard process that asks us for more metadata about our project. This metadata and configuration will differ depending on the template you choose.

Let's investigate the files and folders that the template created:

Notice how we're no longer working with .js files, and we now have .vue files inside of our src directory. A Vue file is known as a Single File Component and it has a template, script, and style tag, allowing us to scope everything to this component only.

This is possible due to our Webpack template, as we have a custom "loader". How does this work? Prior to looking at this, let's take a quick detour and review modern JavaScript build systems.

主站蜘蛛池模板: 文山县| 荆门市| 泗阳县| 苍南县| 罗田县| 桐乡市| 涡阳县| 定南县| 乌兰浩特市| 滕州市| 辽源市| 广灵县| 札达县| 蕉岭县| 丹江口市| 日照市| 台中县| 惠水县| 文登市| 宁河县| 睢宁县| 大同市| 汕尾市| 昂仁县| 汤阴县| 牙克石市| 法库县| 蓬溪县| 绿春县| 澄江县| 秀山| 汾西县| 南溪县| 马尔康县| 屏边| 青海省| 香港 | 祁东县| 溧水县| 嘉禾县| 巢湖市|