加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

vue-cli 3.0 自定义vue.config.js文件,多页构建的方法

发布时间:2020-12-16 23:32:11 所属栏目:百科 来源:网络整理
导读:使用自己基于vue-cli 2.X改造的前端多页脚手架有近1年多时间了,一直没机会升级3.0版本 开始零零碎碎开始写一些功能,顺便分享一下 { const [ globPathHtml,globPathJs,pages,tempSet ] = [ ['./src/modules/**/index.html','template'],// 入口模板正则 ['.

使用自己基于vue-cli 2.X改造的前端多页脚手架有近1年多时间了,一直没机会升级3.0版本

开始零零碎碎开始写一些功能,顺便分享一下

{ const [ globPathHtml,globPathJs,pages,tempSet ] = [ ['./src/modules/**/index.html','template'],// 入口模板正则 ['./src/modules/**/main.js','entry'],// 入口脚本正则 Object.create(null),new Set() ] const getMultiPageConf = (globPath,keyName) => { let [fileList,tempArr,modName] = [glob.sync(globPath),[],null] if (fileList.length !== 0) { for (let entry of fileList) { tempArr = path.dirname(entry,path.extname(entry)).split('/') modName = tempArr[tempArr.length - 1] if (tempSet.has(modName)) { Object.assign(pages[modName],{ [keyName]: entry,'filename': `${modName}.html` }) } else { Reflect.set(pages,modName,{ [keyName]: entry }) && tempSet.add(modName) } } return true } else { if (keyName === 'template') { throw new Error('无法获取多页入口模板') } else if (keyName === 'entry') { throw new Error('无法获取多页入口脚本') } else { throw new Error('无法获取多页信息') } } } try { while (getMultiPageConf(...globPathHtml) && getMultiPageConf(...globPathJs)) return pages } catch (err) { console.log('获取多页数据错误:',err) } })() console.log('pages: ',getPages)

打印结果:

使用:

以上这篇vue-cli 3.0 自定义vue.config.js文件,多页构建的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程之家。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读