1. 在package.json中,写入脚本

"scripts": {

"serve": "vue-cli-service serve",

"build": "vue-cli-service build",

"temp": "node util/template.js"

},

2.在util/template文件夹下,创建通用模版。

main.html:

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="utf-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no,minimal-ui,viewport-fit=cover">

<meta content="yes" name="apple-mobile-web-app-capable">

<meta content="black" name="apple-mobile-web-app-status-bar-style">

<meta name="format-detection" content="telephone=no, email=no">

<meta name="W_design" content="750">

<!-- 页面 page id start-->

<meta name="WT.pagetitle" content=""></meta>

<meta name="WT.pageID" content=""></meta>

<!-- 页面 page id end-->

<title></title>

<script src="./static/base/js/flexible.js"></script>

</head>

<body>

<noscript>

<strong>浏览器版本过低,无法支持此页面,请升级页面;</strong>

</noscript>

<div id="app"></div>

<!-- built files will be auto injected -->

</body>

</html>

----------------------

main.js:

import Vue from 'vue'

import App from './main.vue'

Vue.config.productionTip = false

new Vue({

render: h => h(App),

}).$mount('#app')

---------------------

main.vue:

<template>

<div class="app">

</div>

</template>

<script>

export default {

data() {

return {

};

},

methods: {

},

components: {

}

};

</script>

<style type="text/css" lang="scss" scoped>

</style>

-------------------

3. 在util路径下,创建template.js执行脚本

/**

* 通过模版创建页面

*/

const path = require('path');

const fs = require('fs');

const readlineSync = require('readline-sync');

// 输入需要创建的页面名称

let pageName = readlineSync.question('enter your page name: ');

// 目标模块目录的地址

const pagePath = path.resolve(__dirname, '../src/pages', pageName);

console.log('pagePath',pagePath)

// 模板地址

const templatePath = path.resolve(__dirname, '../util/template');

console.log('templatePath',templatePath)

// 判断目标页面目录是否存在

if (fs.existsSync(pagePath)) {

// 存在指定页面,提示错误并退出程序

console.error(`${pageName} page is exists`)

process.exit()

}

// 创建目标页面目录

fs.mkdirSync(pagePath);

// 需要复制的文件

const copyFiles = ['main.html', 'main.js', 'main.vue'];

const copy = (source) => {

for (const item of source) {

// 读取模板中对应文件的内容

let fileText = fs.readFileSync(path.join(templatePath, item));

// 写入到目标页面中对于的文件中

fs.writeFileSync(path.join(pagePath, item), fileText)

}

}

// 执行复制操作

copy(copyFiles);

console.log('Successful page creation!');

--------------------

/**

* 通过模版创建页面

*/

const path = require('path');

const fs = require('fs');

const readlineSync = require('readline-sync');

// 输入需要创建的页面名称

let pageName = readlineSync.question('enter your page name: ');

// 目标模块目录的地址

const pagePath = path.resolve(__dirname, '../src/pages', pageName);

console.log('pagePath',pagePath)

// 模板地址

const templatePath = path.resolve(__dirname, '../util/template');

console.log('templatePath',templatePath)

// 判断目标页面目录是否存在

if (fs.existsSync(pagePath)) {

// 存在指定页面,提示错误并退出程序

console.error(`${pageName} page is exists`)

process.exit()

}

// 创建目标页面目录

fs.mkdirSync(pagePath);

// 需要复制的文件

const copyFiles = ['main.html', 'main.js', 'main.vue'];

const copy = (source) => {

for (const item of source) {

// 读取模板中对应文件的内容

let fileText = fs.readFileSync(path.join(templatePath, item));

// 写入到目标页面中对于的文件中

fs.writeFileSync(path.join(pagePath, item), fileText)

}

}

// 执行复制操作

copy(copyFiles);

console.log('Successful page creation!');

转载于:https://www.cnblogs.com/Super-scarlett/p/11046923.html

vue cli3--创建通用模版相关推荐

  1. Vue CLI3不兼容IE11打开空白报错SCRIPT1003: 缺少 ‘:‘

    一.问题描述 Vue CLI3打包上线后的代码使用IE11打开后是空白的,控制台报错: SCRIPT1003: 缺少 ':' app.js (304501,83045) 其他浏览器打开没问题,问题定位 ...

  2. linux 使用ssr客户端_【第一期】基于 @vue/cli3 与 koa 创建 ssr 工程

    什么是基于同构代码的 SSR 服务(Server-side rendering based on isomorphic code) 首先,我们需要先明白什么是 spa (single page app ...

  3. Vue CLI3.0 中使用jQuery 和 Bootstrap

    Vue 中使用 jQuery 和 Bootstrap 不是特别符合 Vue 原生的写法,但是有时候又要用,所以放上我的引入设置,供大家参考. 在 Vue CLI2.0 中引入 jQuery 和 Boo ...

  4. vue cli3 绑定域名_使用CLI设置WildFly绑定地址并关闭

    vue cli3 绑定域名 仅使用命令行参数将WildFly绑定到主机名/ IP上非常容易. 我有一个简单的GNU / Linux盒子,可以用它玩各种东西,其中之一就是WildFly. 我使用以下命令 ...

  5. 软件需求规格说明书通用模版_通用需求挑战和机遇

    软件需求规格说明书通用模版 When developing applications there will be requirements that are needed on more than o ...

  6. Vue cli3使用jQuery控件

    背景介绍 由于历史遗留问题需要使用之前基于jQuery的代码,其中还用到了一个基于jQuery的多选控件,环境是vue cli3 导入并配置jQuery 首先通过npm导入jQuery npm ins ...

  7. Vue CLI3 基本使用配置;

    Vue CLI3 开始 安装: npm install -g @vue/cli # OR yarn global add @vue/cli 创建一个项目:  vue create my-project ...

  8. Vue Cli3 项目 vue.config.js 配置

    Vue Cli3 项目 vue.config.js 配置 配置优化 一.js文件最小化处理 二.分割代码 三.图片资源压缩 四.开启gzip压缩 先看一下优化配置之前的文件大小 通过vue-cli3脚 ...

  9. 公司项目vue cli2升级到vue cli3

    背景: 公司项目历时时间较长,通过长时间的迭代,目前项目文件较多(src目录下有2217个文件),系统庞大, 之前通过vue cli2脚手架构建的项目框架,在本地开发时已经明显感觉到吃力(项目首次启动 ...

最新文章

  1. python比较两个xml_python比较2个xml内容的方法
  2. pytorch多进程加载数据
  3. NYOJ 451(组合数+全错位)
  4. android 多线程 场景,精选Android初中级面试题 (三): 深探Handler,多线程,Bitmap
  5. android 类ios actionsheet效果
  6. Docker 从入门到实战视频教程(15 个视频)
  7. VlanIF和Vlan间路由
  8. SQL2000中文版打不上SP4提示用户验证没有通过
  9. 产品经理笔试题分析(一)
  10. dcos 架构官方文档
  11. 如何制作一张完美的VR全景图片?
  12. Mybatis学习笔记-配置Log4j以便查看MyBatis操作数据库的过程
  13. 和chatGPT聊了聊通信,答复如下:
  14. 合工大现代企业管理期末报告--阿里巴巴企业管理模式探究
  15. guava之限流RateLimiter
  16. 论文研读 Rotated Test Problems for Assessing the Performance of MOEAs
  17. ZZ教你卸载 Office 正版增值计划通知 (KB949810)-CHS
  18. 先调用finish() 然后startActivity有什么区别?
  19. 动态规划求解最大子序列和
  20. revi翻模工具【管线角度微调】,那些最不擅长的小事

热门文章

  1. 前端组件化思想与实践
  2. JavaScript笔记2———js的数据类型
  3. c#获取带有汉字的字符串长度
  4. 汇编语言学习之汇编语言源程序的输入
  5. 微软职位内部推荐-Software Engineer
  6. uva10340 Ail in All
  7. DotNetBar 教程
  8. 数据结构上机实践第八周项目6- 猴子选大王(数组版)
  9. Tensorflow(r1.4)API--tf.summary.scalar
  10. SLAM的一些基础知识