Vue CLI 3 Quick Start Guide: Build and maintain Vue.js applications quickly with the standard CLI
()
About this ebook
Build Vue apps the right way using Vue CLI 3. Understand how the building blocks of Vue CLI 3 work including npm, webpack, babel, eslint, plugins, GUI, testing, and SCSS. Import third-party libraries and maintain your project.
Key Features
- Learn to work with Vue CLI 3 both on the command line and with a GUI
- Manage VueJS apps, settings, Vue plugins, and third-party libraries
- Learn how to build Vue apps from scratch using webpack, babel, ES6, vue-router, Jest, Cypress, SCSS, and Git
Book Description
The sprawling landscape of various tools in JavaScript web development is becoming overwhelming. This book will show you how Vue CLI 3 can help you take back control of the tool chain. To that end, we'll begin by configuring webpack, utilizing HMR, and using single-file .vue components. We'll also use SCSS, ECMAScript, and TypeScript. We'll unit test with Jest and perform E2E testing with Cypress.
This book will show you how to configure Vue CLI as your default way of building Vue projects. You'll discover the reasons behind using webpack, babel, eslint, and other modern JavaScript toolchain technologies. You'll learn about the inner workings of each through the lens of Vue CLI 3. We'll explore the extendibility of Vue CLI with the built-in settings, and various core and third-party plugins.
Vue CLI helps you work with Vue components, routers, directives, and services in the Vue ecosystem. While learning these concepts, you'll examine the evolution of JavaScript. You'll learn about use of npm, IIFEs, modules in JavaScript, Common.js modules, task runners, npm scripts, module bundlers, and webpack. You'll get familiar with the reasons why Vue CLI 3 is set up the way it is. You'll also learn to perform linting with ESLint and Prettier.
Towards the end, we'll introduce you to working with styles and SCSS. Finally, we'll show you how to deploy your very own Vue project on Github Pages.
What you will learn
- Work with nvm, install Node.js and npm, use Vue CLI 3 with no configuration, via the command line and the graphical user interface
- Build a Vue project from scratch using npm and webpack, and learn about hot module replacement
- Work with Babel settings, configurations, and presets
- Work with Vue plugins, including testing plugins such as Jest and Cypress
- Write, run, and watch unit and E2E tests using TDD assertions in the red-green-refactor cycle
- Work with Vue router and use, nested, lazy-loading, and dynamic routes
- Add SCSS to your projects and work with third-party Vue plugins
- Deploy your Vue apps to Github Pages
Who this book is for
This book is for existing web developers and developers who are new to web development. You must be familiar with HTML, CSS, and JavaScript programming. Basic knowledge of the command line will be helpful but is not necessary.
Read more from Ajdin Imsirovic
Vue.js Quick Start Guide: Learn how to build amazing and complex reactive web applications easily using Vue.js Rating: 0 out of 5 stars0 ratingsElm Web Development: An introductory guide to building functional web apps using Elm Rating: 0 out of 5 stars0 ratingsBootstrap 4 Cookbook Rating: 0 out of 5 stars0 ratings
Related to Vue CLI 3 Quick Start Guide
Related ebooks
Vue.js 3 By Example: Blueprints to learn Vue web development, full-stack development, and cross-platform development quickly Rating: 0 out of 5 stars0 ratingsLearn Vue.js: The Collection Rating: 0 out of 5 stars0 ratingsJump Start Vue.js Rating: 4 out of 5 stars4/5Working with Vue.js Rating: 0 out of 5 stars0 ratingsVue.js 3 for Beginners: Learn the essentials of Vue.js 3 and its ecosystem to build modern web applications Rating: 0 out of 5 stars0 ratingsASP.NET Core Essentials Rating: 0 out of 5 stars0 ratingsVue.js 2 Design Patterns and Best Practices: Build enterprise-ready, modular Vue.js applications with Vuex and Nuxt Rating: 0 out of 5 stars0 ratingsMastering Spring 5.0 Rating: 5 out of 5 stars5/5Mastering Visual Studio 2017 Rating: 0 out of 5 stars0 ratingsFull-Stack Web Development with GraphQL and React: Taking React from frontend to full-stack with GraphQL and Apollo Rating: 0 out of 5 stars0 ratingsVuex Quick Start Guide: Centralized State Management for your Vue.js applications Rating: 0 out of 5 stars0 ratingsBuilding Forms with Vue.js: Patterns for building and scaling complex forms with great UX Rating: 0 out of 5 stars0 ratingsASP.NET Core 5 and Angular: Full-stack web development with .NET 5 and Angular 11 Rating: 0 out of 5 stars0 ratingsIsomorphic JavaScript Web Development: Universal JavaScript with React and Node Rating: 0 out of 5 stars0 ratingsComplete Vue.js 2 Web Development: Practical guide to building end-to-end web development solutions with Vue.js 2 Rating: 0 out of 5 stars0 ratingsPractical WebAssembly: Explore the fundamentals of WebAssembly programming using Rust Rating: 0 out of 5 stars0 ratingsAngularJS Web Application Development Blueprints Rating: 0 out of 5 stars0 ratingsAngular Projects: Build modern web apps by exploring Angular 12 with 10 different projects and cutting-edge technologies Rating: 0 out of 5 stars0 ratingsEnd to End GUI Development with Qt5: Develop cross-platform applications with modern UIs using the powerful Qt framework Rating: 0 out of 5 stars0 ratingsHands-On Serverless Applications with Go: Build real-world, production-ready applications with AWS Lambda Rating: 0 out of 5 stars0 ratingsVue.js: 11 Practical Projects Rating: 0 out of 5 stars0 ratingsLearn Angular: 4 Angular Projects Rating: 0 out of 5 stars0 ratingsVue.js 2 Web Development Projects: Learn Vue.js by building 6 web apps Rating: 0 out of 5 stars0 ratingsLearning Node.js Development: Learn the fundamentals of Node.js, and deploy and test Node.js applications on the web Rating: 0 out of 5 stars0 ratings
Internet & Web For You
Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Coding For Dummies Rating: 5 out of 5 stars5/5No Place to Hide: Edward Snowden, the NSA, and the U.S. Surveillance State Rating: 4 out of 5 stars4/5How to Be Invisible: Protect Your Home, Your Children, Your Assets, and Your Life Rating: 4 out of 5 stars4/5The Hacker Crackdown: Law and Disorder on the Electronic Frontier Rating: 4 out of 5 stars4/5Six Figure Blogging Blueprint Rating: 5 out of 5 stars5/5The Gothic Novel Collection Rating: 5 out of 5 stars5/5Social Engineering: The Science of Human Hacking Rating: 3 out of 5 stars3/5Mike Meyers' CompTIA Security+ Certification Guide, Third Edition (Exam SY0-601) Rating: 5 out of 5 stars5/5Python QuickStart Guide: The Simplified Beginner's Guide to Python Programming Using Hands-On Projects and Real-World Applications Rating: 0 out of 5 stars0 ratingsEverybody Lies: Big Data, New Data, and What the Internet Can Tell Us About Who We Really Are Rating: 4 out of 5 stars4/5Beginner's Guide To Starting An Etsy Print-On-Demand Shop Rating: 0 out of 5 stars0 ratingsThe $1,000,000 Web Designer Guide: A Practical Guide for Wealth and Freedom as an Online Freelancer Rating: 5 out of 5 stars5/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Kill All Normies: Online Culture Wars From 4Chan And Tumblr To Trump And The Alt-Right Rating: 3 out of 5 stars3/5How to Disappear and Live Off the Grid: A CIA Insider's Guide Rating: 0 out of 5 stars0 ratingsGet Rich or Lie Trying: Ambition and Deceit in the New Influencer Economy Rating: 0 out of 5 stars0 ratingsPodcasting For Dummies Rating: 4 out of 5 stars4/5How To Start A Profitable Authority Blog In Under One Hour Rating: 5 out of 5 stars5/5How To Make Money Blogging: How I Replaced My Day-Job With My Blog and How You Can Start A Blog Today Rating: 4 out of 5 stars4/5The Digital Marketing Handbook: A Step-By-Step Guide to Creating Websites That Sell Rating: 5 out of 5 stars5/5Wireless Hacking 101 Rating: 5 out of 5 stars5/5HTML in 30 Pages Rating: 5 out of 5 stars5/5Wordpress for Beginners: The Easy Step-by-Step Guide to Creating a Website with WordPress Rating: 5 out of 5 stars5/5More Porn - Faster!: 50 Tips & Tools for Faster and More Efficient Porn Browsing Rating: 3 out of 5 stars3/5Tor and the Dark Art of Anonymity Rating: 5 out of 5 stars5/5An Ultimate Guide to Kali Linux for Beginners Rating: 3 out of 5 stars3/5
Reviews for Vue CLI 3 Quick Start Guide
0 ratings0 reviews
Book preview
Vue CLI 3 Quick Start Guide - Ajdin Imsirovic
Vue CLI 3 Quick Start Guide
Build and maintain Vue.js applications quickly with the standard CLI
Ajdin Imsirovic
BIRMINGHAM - MUMBAI
Vue CLI 3 Quick Start Guide
Copyright © 2019 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Pavan Ramchandani
Acquisition Editor: Siddharth Mandal
Content Development Editor: Roshan Kumar
Technical Editor: Snehal Dalmet
Copy Editor: Safis Editing
Project Coordinator: Namrata Swetta
Proofreader: Safis Editing
Indexer: Priyanka Dhadke
Graphics: Jisha Chirayil
Production Coordinator: Aparna Bhagat
First published: April 2019
Production reference: 1300419
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78995-034-2
www.packtpub.com
Thanks to my family and friends for their support during the writing of this book.
– Ajdin Imsirovic
mapt.io
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
Packt.com
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.
At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Contributors
About the author
Ajdin Imsirovic is a full-stack web developer who has published several courses on the subject of web design and web development. He has also authored three books, Bootstrap 4 Cookbook, Elm Web Development, and Vue.js Quick Start Guide. In his fourth book, Vue CLI 3 Quick Start Guide, he introduces readers to the rich ecosystem of frontend tooling and best practices.
About the reviewer
Bogdan-Alin Bâlc is a software architect/tech lead with a passion for UI technologies. He has worked with JavaScript for the past 13 years, from the emergence of jQuery and Ajax to state-of-the-art solutions such as React, Angular, Ember.js, and Vue.js. When he is not fiddling with some new coding challenge, he spends his time with friends and family, watching sports or movies. Nowadays, he channels most of his efforts into making Vulcan Digital Reforging, one of the most successful and creative start-ups in Cluj. His passion for Vue.js pushed him to collaborate on other great books, such as Learning Vue.js, Vue.js 2 Cookbook, and Vue.js by Example.
Packt is searching for authors like you
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Table of Contents
Title Page
Copyright and Credits
Vue CLI 3 Quick Start Guide
Dedication
About Packt
Why subscribe?
Packt.com
Contributors
About the author
About the reviewer
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Download the color images
Conventions used
Get in touch
Reviews
Introducing Vue CLI 3
Technical requirements
Setting up Vue CLI 3 on our system
Is Vue CLI 3 already available?
Installing Node.js using Node Version Manager
Why install NVM?
Installing NVM on Windows
Installing Vue CLI 3
Installing VS Code
Using Vue CLI with no configuration
The benefits of using Vue CLI 3
Default toolchain, fatigue level zero
Vue CLI 3 default app via the command line
Vue CLI 3 default app via the UI
Summary
Webpack in Vue CLI 3
The evolution of the JS language
The script tag
Immediately Invoked Function Expressions
The problem with IIFEs
Sharing third-party libraries in a team environment with NPM
JavaScript task runners and NPM scripts
Modules in JavaScript
Working with modules in Node.js
Module bundlers, a way to use modules in the browser
What is webpack?
How webpack works
Building a new project and running webpack on it
Running webpack on a project
Adding a Vue project via NPM and using webpack with it
Adding our Vue component as a JavaScript module
Compiling JavaScript modules with webpack
Adding options with the help of the webpack configuration file
Adding an HTML file so that we can render our Vue component
Giving webpack the ability to output an HTML file
Adding a .vue file as a JavaScript module
Adding a webpack loader to work with .vue files
Fixing the issue with our index.html file
Delivering HTML files via webpack with the help of html-webpack-plugin
Understanding Hot Module Replacement in Vue
Observing HMR updates
Summary
Babel in Vue CLI 3
Understanding Babel
The building blocks of @vue/cli-plugin-babel
Babel 7 in @vue/cli-plugin-babel
The role of babel-loader in @vue/cli-plugin-babel
The role of @vue/babel-preset-app
Other features of @vue/cli-plugin-babel
Using Babel and webpack in Vue 2 without Vue CLI
Installing the necessary NPM packages
Running webpack with ES5 code
Adding webpack-dev-server
Updating the methods option to ES6 syntax
Adding babel-loader to our webpack configuration
Updating our webpack configuration to work with babel
The problem with the this keyword in arrow functions in Vue
Recommended solutions to keyword problems
Adding one counter app
Summary
Testing in Vue CLI 3
Understanding Vue plugins
Beginning testing on a brand new Vue app
Adding a new project with Vue CLI UI
Adding the Jest plugin to our Vue app
Examining the updates
Adding the code for our Vue application
Writing our first unit test inside a Vue app with Jest
Running our first unit test inside the Vue CLI UI
Importing mount from test-utils and writing another unit test
Mounting the component to be tested
Writing a failing assertion
Writing a passing assertion
Triggering a button click in our test
Test-driven development in Vue CLI 3
Improving our tests in Vue CLI 3
Watching our tests in Vue CLI 3
Writing end-to-end tests with Cypress
Introducing Cypress
Adding a Cypress plugin to our project
Verifying updates to package.json made by the Cypress plugin installation
Updating Cypress tests in our Vue app
Summary
Vue CLI 3 and Routing
Adding a new Vue project with vue-router and vuex
Configuring preset options through VS Code's command line
Adding vue-router and vuex
Adding ESLint and Prettier
Finishing the configuration
Installing all the plugins for our new project
Serving our project from the Vue CLI UI
Running the serve task from the UI
Working with routes in vue-router
Inspecting the two default routes
Inspecting project files
The contents of main.js
The App.vue file and router-link navigation
Rendering a Vue instance and mounting it into #app
Running the build task from the UI
Serving the app in production mode from the UI
Some basics of working with routes
The router-view tag needs to be nested
Using named routes
Navigating to a route by triggering a method of a Vue instance
Working with nested routes
Lazy- loading routes
Working with dynamic routes
Summary
Using ESLint and Prettier in Vue CLI 3
What ESLint is, and how to configure it on its own
Installing npm packages globally versus installing npm packages locally
What is Prettier?
Running locally-installed npm modules on the command line using npx
Installing Prettier globally and running it on index.html
Running Prettier with npx
Working with ESLint
Installing ESLint globally and unsuccessfully running it from the command line
Running eslint --init command
Understanding the structure of .eslintrc.js config file
Running ESLint on a JavaScript file
Updating error level rules in ESLint
Configuring ESLint in Vue CLI 3
Setting up ESLint configurations in Vue CLI 3 GUI
Using ESLint and Prettier together in a Vue CLI 3 UI project
Summary
Improving CSS with SCSS
Installing Bootstrap + Vue
Adding BootstrapVue as a plugin
Using the bootstrap-vue plugin to add styles to our project
Using SCSS in our project
Dealing with errors
Writing some SCSS in our project
Overriding bootstrap-vue styles
Using variables, mixins, and interpolation
Using Sassmeister to practice SCSS
Using SCSS mixins and interpolation in our Vue project
Summary
Deploying Vue CLI 3 Apps on GitHub Pages
Installing GitHub Desktop app
Understanding how Git works
Starting a new Vue app and tracking changes with Git
Committing changes to our app
The three trees concept
Branching in Git
Merging branches
Registering a new GitHub account
Adding origin/master using GitHub Desktop
Publishing your local repository
Publishing our project on GitHub Pages
Getting our project ready to be published
Updating the Vue configuration file
Saving changes and pushing them to the remote repository with GitHub Desktop
Debugging your GitHub pages deployment
Summary
Other Books You May Enjoy
Leave a review - let other readers know what you think
Preface
Vue began as a project of a single person, Evan You. It is amazing that it has gotten to the point where it is today: a contender for the spot of the favorite frontend framework, competing with the corporate-backed React and Angular.
Of course, these are not the only frontend frameworks, but the trio of Vue, React, and Angular seem to be the most popular, with the internet buzzing with comparisons of these frameworks and experiences with them. It's not uncommon to come across an article that compares Vue and React, for example, or a blog post on ten ways that Vue is better than Angular. Regardless of whether these articles are someone's opinion, or clickbait, or statement of the facts, there must be some truth to these claims.
What was the reason for Vue's success? Dedication, hard work, or luck? Probably a bit of each. But another key to Vue's success was Evan's obvious priority of making things easy for the developer. Vue's no longer developed by a single person, but it is still very approachable. The community has kept the gist of what Vue was all about from the beginning: an easy-to-use framework that gets out of your way and just lets you code.
Vue CLI is another example of this. Besides a command-line interface that's up to par with other modern frontend frameworks, Vue CLI 3 sets a new standard in frontend JavaScript frameworks, and comes with a graphical user interface (GUI). This interface makes it a breeze to set up, extend, run, and serve a Vue project.
When you pair this addition