Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用 Vue CLI 4 初始化项目 #6

Open
409915016 opened this issue Sep 16, 2020 · 1 comment
Open

使用 Vue CLI 4 初始化项目 #6

409915016 opened this issue Sep 16, 2020 · 1 comment
Assignees
Labels
Milestone

Comments

@409915016
Copy link
Owner

409915016 commented Sep 16, 2020

原项目是基于古老的 Vue CLI 建成的,使用的仍是 webpack 2,构建依赖等问题,项目在构件时出现报错,详细见 #5

新版的 Vue CLI 拥有更多的功能,解决了以前没办法实现的问题,与其在原构建方案中修复问题,不如拥抱新构建版本。

现在重新使用 Vue CLI 4 初始化模板,将源代码迁移到模板里,并构建出多页面应用

@409915016 409915016 self-assigned this Sep 16, 2020
@409915016 409915016 added the feature 新特性 label Sep 16, 2020
@409915016
Copy link
Owner Author

409915016 commented Sep 16, 2020

原有的应用入口文件存放在 src/entries 目录中

src
├─entries
│      admin-main.js
│      init.js
│      main.js
入口文件 调整后的新入口文件 地址 描述
admin-main.js admin/app.js http://localhost:8080/admin 管理后台应用
init.js init/app.js http://localhost:8080/init 初始化向导应用
main.js filmy/app.js http://localhost:8080/filmy 项目前端应用

修改后的入口文件

src
├─pages
│  ├─admin
│  │      app.js
│  │
│  ├─filmy
│  │      app.js
│  │
│  └─init
│          app.js

在新的 Vue CLI 4 创建的项目,配置文件 vue.config.js 通过 page 参数导入多个页面对象,即可构建出多页面应用:

const pageSet = (name, title = "") => {
    return {
        [`${name}`] : {
            entry: `src/pages/${name}/app.js`,
            template: `public/${name}.html`,
            filename: `${name}.html`,
            title: title ? title: name
        }
    }
}

const pages = {
    ...pageSet('init'),
    ...pageSet('admin'),
    ...pageSet('filmy'),
}

module.exports = {
    //...
    pages
}

那么在开发项目时,通过下面的地址访问相关页面

http://localhost:8080/init
http://localhost:8080/admin
http://localhost:8080/filmy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant