[Vue] Code split by route in Vuejs

Source: Internet
Author: User

In the lesson I show how to use Webpack to code split based on the route in Vuejs. Code splitting is a useful tool to help eliminate unused code and only load what ' s necessary.

Additional Resources https://router.vuejs.org/en/advanced/lazy-loading.html

After generate the project by VUE-CLI, make sure those dependencies were installed already:

NPM I babel-eslint babel-plugin-syntax-dynamic-import eslint-plugin-import-d

. Eslintrc.js:

Module.exports = {  true,  ' babel-eslint '  },  extends: [ "Plugin:vue/essential", "@vue/prettier"]};

. BABELRC:

{  "presets": ["@vue/app"],  "plugins": ["Syntax-dynamic-import"]} 

Routes.js:

Import vue from "Vue"; import Router from"Vue-router"; Const Home= () = Import (/*webpackchunkname: "Home"*/"./views/home.vue"); const About= () = Import (/*webpackchunkname: "About"*/"./views/about.vue"); Vue.use (Router); Exportdefault NewRouter ({routes: [{path:"/", Name:"Home", Component:home}, {path:"/about", Name:"About", Component:about}]});

[Vue] Code split by route in Vuejs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.