vite实现终端自定印打印文字

1.安装插件picocolors,一个可以修改终端字符颜色的npm包

cnpm add picocolors

2.新建自定义插件文件(viteBuildInfo.ts)

import type { Plugin } from "vite";
import { green, blue, bold } from "picocolors";
export function viteBuildInfo():Plugin{
	return {
		name:'vite:buildInfo',
		buildStart(){
			console.log(bold(green(`欢迎使用${blue('vue')},感觉不错的哈请给个赞呗`)))
		}
	}
}

3.也可以使用艺术字来替换文本
https://www.bootschool.net/ascii-art/animals

                         ___                 
                     .-'`     `'.            
              __    /  .-. .-.   \           
           .'`__`'.| /  ()|  ()\  \          
          / /`   `\\ |_ .-.-. _|  ;  __      
          ||     .-'`  (/`|`\) `-./'`__`'.   
          \ \. .'                 `.`  `\ \  
           `-./  _______            \    ||  
              | |\      ''''---.__   |_./ /  
              ' \ `'---..________/|  /.-'`   
               `.`._            _/  /        
                 `-._'-._____.-' _.`         
                  _,-''.__...--'`            
              _.-'_.    ,-. _ `'-._          
           .-' ,-' /   /   \\`'-._ `'.       
         <`  ,'   /   /     \\    / /        
          `.  \  ;   ;       ;'  / /_        
    __   (`\`. \ |   |       ||.' // )       
 .'`_ `\(`'.`.\_\|   |    o  |/_,'/.' )      
/ .' `; |`-._ ` /;    \     / \   _.-'       
| |  (_/  (_..-' _\    `'--' | `-.._)        
; \        _.'_.' / /'.___.; \               
 \ '-.__.-'_.'   ; '        \ \              
  `-.,__.-'      | ;         ; '             
                 | |         | |             
                 | |         / /mx           
               .-' '.      ,' `-._           
             /`    _ `.   /  _    `.         
            '-/ / / `\_) (_/` \  .`,)        
             | || |            | | |         
             `-'\_'            (_/-'                                                       

4.vite.config.ts中引入viteBuildInfo.ts插件即可
只需要在plugin內引入就可以了,就不贴代码了

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现Vue3 + Vite + Electron的打印功能,你可以按照以下步骤进行。 1. 安装Electron 在项目中安装Electron,你可以使用npm命令进行安装: ``` npm install electron --save-dev ``` 2. 创建Electron应用程序 在应用程序的主目录中创建一个名为main.js的文件,并在其中创建一个Electron应用程序: ```javascript const { app, BrowserWindow } = require('electron') function createWindow () { const win = new BrowserWindow({ width: 800, height: 600, webPreferences: { nodeIntegration: true } }) win.loadURL('http://localhost:3000') win.webContents.on('did-finish-load', () => { win.webContents.print() }) } app.on('ready', createWindow) ``` 在这个示例中,我们创建了一个Electron窗口,并在窗口加载完成时执行打印操作。 3. 打印Vue3组件 在Vue3组件中,你可以使用window.print()方法来实现打印功能。例如,在一个名为PrintButton.vue的组件中: ```html <template> <button @click="print">打印</button> </template> <script> export default { methods: { print() { window.print() } } } </script> ``` 在这个示例中,我们在组件中创建了一个打印按钮,并在按钮点击时执行打印操作。 4. 运行应用程序 现在,你可以在终端运行Electron应用程序,并访问http://localhost:3000来测试打印功能: ``` electron . ``` 如果一切正常,你应该能够在Electron窗口中看到你的Vue3应用程序,并且能够通过按钮打印内容。 这就是使用Vue3 + Vite + Electron实现打印功能的基本步骤。当然,你还可以根据自己的需求进行更多的定制和优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值