Browse Source

work properly on changes in view definitions

master
Marek Piasecki 2 years ago
parent
commit
7cf73f190d
  1. 37
      vite.config.js

37
vite.config.js

@ -3,8 +3,12 @@ import { resolve } from 'path'
import { defineConfig } from 'vite';
import { name } from './package.json'
let viewPaths = {} // view: [path]
let pathViews = {} // path: [view]
function duplicate(obj){ return JSON.parse(JSON.stringify(obj)) }
function without(el, arr) { return arr.filter(function(e){ if(e != el) { return e } }) }
function proRouterViews() {
let views = {}
return {
name: 'pro-router-views',
transformIndexHtml(html) {
@ -18,13 +22,36 @@ function proRouterViews() {
let viewRegExp = /tag view-((\w|\S)+)( |\n)/g
let result = null
let views_str = ""
let views = pathViews[id] ||= []
let missingDeclarations = duplicate(views)
while(result = viewRegExp.exec(src)) {
let view = result[1]
if(view != 'not_found' && !views[view]){
views[view] = true
views_str += "Views.push(\""+ result[1] +"\");"
if(view != 'not_found'){
let paths = viewPaths[view] ||= []
missingDeclarations = without(view, missingDeclarations)
if(!views.includes(view)){
views.push(view)
if(!paths.includes(id)){
paths.push(id)
}
}
if(paths[0] == id){
views_str += "Views.push(\""+ view +"\");"
}
}
}
}
missingDeclarations.forEach(function(view){
let paths = viewPaths[view] ||= []
if((paths[0] == id) && (paths.length > 1)){
views_str += "Views.push(\""+ view +"\");"
} else {
paths = without(id, paths)
views = without(view, views)
}
})
return { code: views_str+src, map: null }
}
}

Loading…
Cancel
Save