[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
<>一、应用场景:
多个项目需要用到共同的组件,这时用多页面vue应用再适合不过了。但是这多个项目需要分别部署在不同服务器上,所以需要我们针对每个项目(即每个页面)进行单独打包。
<>二、单独打包某个页面:
这里我们以单独打包vue多页面应用中的其中一个页面(detail.html)为示例进行说明。
1)创建新的打包模式:新建文件".env.detail"
# set ENV NODE_ENV = 'production' # 需要打包的页面 PAGE_NAME = 'detail'
2)配置打包指令:修改package.json文件
// package.json文件部分代码 "scripts": { "serve": "vue-cli-service serve", "build":
"vue-cli-service build", "build:detail": "vue-cli-service build --mode detail",
},
3)动态配置pages: 修改vue.config.js文件
// vue.config.js文件部分内容 //
getPages方法生成pages对象:没有参数(即不指定打包的页面)时,打包所有页面;若有参数(即指定打包页面)时, const path = require
("path"); const glob = require("glob"); const baseDir = filePath => path.
basename(path.dirname(filePath)); function getPages(pageName) { let map = {};
// 多页面(整个项目)打包 if (!pageName) { const PAGE_PATH = path.resolve(__dirname,
"./src/pages"); let entryFiles = glob.sync(PAGE_PATH + "/*/*.html"); entryFiles.
forEach(filePath => { let filename = baseDir(filePath); let tmpArr = filePath.
split("/"); let tmp = tmpArr.splice(0, tmpArr.length - 1); map[filename] = {
entry: tmp.join("/") + "/" + "main.js", template: filePath, filename: filename +
".html" }; }); console.log(map) return map; } // 指定单页面打包 map[pageName] = { entry
: "src/pages/"+pageName+"/main.js", template: "src/pages/"+pageName+
"/index.html", filename: pageName + ".html" } console.log(map) return map }
const pages = getPages(process.env.PAGE_NAME); module.exports = { publicPath:
"/", pages: pages }