Vue-cli multi-page project practice page 1/2, vue-cli2 page

Source: Internet
Author: User
Tags glob

Vue-cli multi-page project practice page 1/2, vue-cli2 page

This article introduces vue-cli multi-page engineering practices and shares them with you as follows:

Src directory structure

Because it is a custom setting, the directory structure under src needs to be fixed, and the conventions are greater than the configuration.

Src directory structure:

Src/components/modules/# multi-page index/# index single page index.html main. js # entry file page1/index.html main. js group/page2/index.html main. js

Configuration in build

Utils. js added:

// Match fileslet glob = require ('glob');/*** obtain a specific file in the pan path using globPath */exports. getEntities = function (path) {let entities = {}; glob. sync (path ). forEach (function (entity) {let moduleName = entity. split ('/'). slice (-2,-1); entities [moduleName] = entity}); // eg: {main :'. /src/module/index/main. js', test :'. /src/module/group/test/main. js '} return entities ;};

Modify Input and Output in webpack. base. conf. js:

Module. exports = {// retrieve the entry file entry through traversal: utils. getEntities (". /src/modules/**/main. js "),... plugins: []};/***** generate <module>/index.html */let utils = require ('. /utils ') let pages = utils. getEntities (". /src/modules/**/index.html "); for (let page in pages) {let filename =" index.html "; if (page! = 'Index') {filename = page + "/index.html";} module. exports. plugins. push (new HtmlWebpackPlugin ({filename: filename, template: pages current 1/2 page12. Next page

Related Article

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.