| 
									
										
										
										
											2023-08-01 00:28:19 +00:00
										 |  |  | import { defineConfig } from 'vite' | 
					
						
							|  |  |  | import vue from '@vitejs/plugin-vue' | 
					
						
							|  |  |  | import { readFileSync } from 'fs'; | 
					
						
							|  |  |  | import { read, utils } from 'xlsx'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default defineConfig({ | 
					
						
							|  |  |  |   assetsInclude: ['**/*.xlsx'], // xlsx file should be treated as assets
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   plugins: [ | 
					
						
							|  |  |  |     vue(), | 
					
						
							|  |  |  |     { // this plugin handles ?sheetjs tags
 | 
					
						
							|  |  |  |       name: "vite-sheet", | 
					
						
							| 
									
										
										
										
											2025-03-31 02:09:31 +00:00
										 |  |  |       transform(_code, id) { | 
					
						
							| 
									
										
										
										
											2023-08-01 00:28:19 +00:00
										 |  |  |         if(!id.match(/\?sheetjs$/)) return; | 
					
						
							|  |  |  |         var wb = read(readFileSync(id.replace(/\?sheetjs$/, ""))); | 
					
						
							|  |  |  |         var data = utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]); | 
					
						
							| 
									
										
										
										
											2024-06-03 00:59:49 +00:00
										 |  |  |         return `export default JSON.parse('${JSON.stringify(data).replace(/\\/g, "\\\\")}')`; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { // this plugin handles ?html tags
 | 
					
						
							|  |  |  |       name: "vite-sheet-html", | 
					
						
							| 
									
										
										
										
											2025-03-31 02:09:31 +00:00
										 |  |  |       transform(_code, id) { | 
					
						
							| 
									
										
										
										
											2024-06-03 00:59:49 +00:00
										 |  |  |         if(!id.match(/\?html/)) return; | 
					
						
							|  |  |  |         var wb = read(readFileSync(id.replace(/\?html/, ""))); | 
					
						
							|  |  |  |         var html = utils.sheet_to_html(wb.Sheets[wb.SheetNames[0]]); | 
					
						
							|  |  |  |         return (`export default JSON.parse('${JSON.stringify(html).replace(/\\/g, "\\\\")}')`); | 
					
						
							| 
									
										
										
										
											2023-08-01 00:28:19 +00:00
										 |  |  |       } | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { // this plugin handles ?b64 tags
 | 
					
						
							|  |  |  |       name: "vite-b64-plugin", | 
					
						
							| 
									
										
										
										
											2025-03-31 02:09:31 +00:00
										 |  |  |       transform(_code, id) { | 
					
						
							| 
									
										
										
										
											2023-08-01 00:28:19 +00:00
										 |  |  |         if(!id.match(/\?b64$/)) return; | 
					
						
							|  |  |  |         var path = id.replace(/\?b64/, ""); | 
					
						
							|  |  |  |         var data = readFileSync(path, "base64"); | 
					
						
							|  |  |  |         return `export default '${data}'`; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   ] | 
					
						
							|  |  |  | }); |