Refer to our previous blog to install Vue.js and CLI, and create a basic project. This article will tell you how to use CLI services and make your app more functional and fast. Follow the steps and use CLI services without hustle.
Step 1: Use the Binary
@vue/cli-service will install a binary named vue-cli-service inside a Vue CLI project. You can easily access this binary as vue-cli-service in npm scripts or from terminal access the binary as ./node_modules/.bin/vue-cli-service.
Below is the code you will see in the package.json of your project as the default preset
You can also invoke these scripts by using either Yarn or npm.
In case you have npx available with you (must be bundled with an updated version of npm), it will allow you to invoke the binary with
The below is the Webpack Analyzer from the GUI
Source: cli.vuejs.org
Step 2: vue-cli-service server
The command vue-cli-service server starts a dev server which is based on webpack-dev-server. This server comes with Hot-Module-Replacement (HMR) working differently.
Along with the command line flags, you can configure the dev server with the help of devServer field in vue.config.js.
Step 3: vue-cli-service build
vue-cli-service build helps in producing a production ready bundle in the directory named dist/, with auto vendor chunk for better chaching and minification for JS/HTML/CSS.
There are some useful flags:
- -modern create your application using Modern Mode, sending native ES2015 code to contemporary browsers that support it with automatic fallback to a legacy bundle.
- -target allows you to develop any component(s) inside your Vuejs project as web components or as a library. See Build Targets for further details.
- -report and - -report-json will produce reports based on the build statistics that will allow you to assess the size of the modules in your bundle.
Step 4: vue-cli-service inspect
To examine the webpack configuration inside a Vue, use vue-cli-service inspect. For further information, see Examining Webpack Configuration.
Step 5: Checking available commands
Certain CLI plugins will send vue-cli-service additional commands. For instance, the vue-cli-service lint command is injected by @vue/cli-plugin-eslint. Run the following command to view all inserted commands:
Moreover, you can use the following to discover each command's possible options:
Step 6: Skipping Plugins
By specifying the name of the plugin with the —skip-plugins option, you can omit particular plugins from being used with a command:
By giving a list of plugin names separated by commas or by repeating the argument, you can skip more than one plugin:
The same method used to resolve plugin names during installation is used here.
Step 7: Caching and Parallelization
cache-loader Vue/Babel/TypeScript compilers by default. You will find node modules/.cache is where files are cached; if you're having compilation problems, always try removing the cache directory first.
When the computer has more than one CPU core, the thread-loader will be activated for Babel/TypeScript translation.
Git Hooks
@vue/cli-service pre installs yorkie that enables you to specify Git hooks with the help of the gitHooks field in your package-json:
Configuration without Ejecting
vue create projects don't require any additional configuration and are ready to go. Most of the time, all you have to do is choose the features you want from the interactive prompts because the plugins are made to cooperate with one another.
We are aware, however, that it is impractical to meet every requirement and that a project's requirements may evolve over time. Without ever having to eject, Vue CLI projects let you configure practically every aspect of the tooling. For more information, go to the Config Reference.
No comments:
Post a Comment