Browse Source

prototype of vite plugin for automatic view declaration

master
Marek Piasecki 2 years ago
parent
commit
cffe8b94e7
  1. 2
      src/main.imba
  2. 28
      vite.config.js

2
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
<self><h1> 'a'

28
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('<head>', '<head><script>window.Views=[];</script>')
},
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,

Loading…
Cancel
Save