|
@ -3,8 +3,12 @@ import { resolve } from 'path' |
|
|
import { defineConfig } from 'vite'; |
|
|
import { defineConfig } from 'vite'; |
|
|
import { name } from './package.json' |
|
|
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() { |
|
|
function proRouterViews() { |
|
|
let views = {} |
|
|
|
|
|
return { |
|
|
return { |
|
|
name: 'pro-router-views', |
|
|
name: 'pro-router-views', |
|
|
transformIndexHtml(html) { |
|
|
transformIndexHtml(html) { |
|
@ -18,13 +22,36 @@ function proRouterViews() { |
|
|
let viewRegExp = /tag view-((\w|\S)+)( |\n)/g |
|
|
let viewRegExp = /tag view-((\w|\S)+)( |\n)/g |
|
|
let result = null |
|
|
let result = null |
|
|
let views_str = "" |
|
|
let views_str = "" |
|
|
|
|
|
let views = pathViews[id] ||= [] |
|
|
|
|
|
let missingDeclarations = duplicate(views) |
|
|
|
|
|
|
|
|
while(result = viewRegExp.exec(src)) { |
|
|
while(result = viewRegExp.exec(src)) { |
|
|
let view = result[1] |
|
|
let view = result[1] |
|
|
if(view != 'not_found' && !views[view]){ |
|
|
if(view != 'not_found'){ |
|
|
views[view] = true |
|
|
let paths = viewPaths[view] ||= [] |
|
|
views_str += "Views.push(\""+ result[1] +"\");" |
|
|
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 } |
|
|
return { code: views_str+src, map: null } |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|