From cffe8b94e73ad6bff401dff51ca3ac4e7549d3f4 Mon Sep 17 00:00:00 2001 From: Marek Piasecki Date: Sat, 14 Jan 2023 21:04:40 +0100 Subject: [PATCH] prototype of vite plugin for automatic view declaration --- src/main.imba | 2 +- vite.config.js | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main.imba b/src/main.imba index a1574fc..e9be03c 100644 --- a/src/main.imba +++ b/src/main.imba @@ -10,7 +10,7 @@ let helpers = toPairs: toPairs flatten: flatten -R.init(helpers: helpers, views: ['a', 'b', 'c'], root: 'a', render: imba.commit) +R.init(helpers: helpers, root: 'a', render: imba.commit) tag view-a

'a' diff --git a/vite.config.js b/vite.config.js index ccee84e..02e9b39 100644 --- a/vite.config.js +++ b/vite.config.js @@ -3,8 +3,34 @@ import { resolve } from 'path' import { defineConfig } from 'vite'; import { name } from './package.json' +function proRouterViews() { + + return { + name: 'pro-router-views', + transformIndexHtml(html) { + return html.replace('', '') + }, + + transform: { + order: 'pre', + handler(src, id) { + if (/\.imba$/.test(id)) { + let viewRegExp = /tag view-((\w|\S)+)( |\n)/g + let result = null + let views = "" + while(result = viewRegExp.exec(src)) { + views += "Views.push(\""+ result[1] +"\");" + } + return { code: views+src, map: null } + } + } + } + } +} + + export default defineConfig({ - plugins: [imba()], + plugins: [proRouterViews(), imba()], build: { lib: { name: name,