laybot-vite-dev 1.0.7 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/package.json +13 -3
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
import w from"node:fs";import F from"node:path";var g=Object.freeze({srcRoot:"/src",viewsDir:"/src/views",htmlFallback:"index.html",debug:!1,toSrcPrefixes:["/api/","/route/","/mock/","/store/","/utils/","/plugin/","/plugins/","/components/","/partials/","/laybot/","/static/","/app/","/platform/","/service/"],stripPrefixes:["/assets/"],backendPrefixes:[],pageExcludePrefixes:[],extensionlessRoutes:!1,extensionlessFallbackToIndex:!1,locale:{enabled:!1,defaultLang:"zh-CN",strategy:"prefix_except_default",prefixes:[],aliases:{},fallbackToDefaultViews:!0}});function m(e){let t=[],r=new Set;for(let s of e||[]){let n=String(s||"").trim();n&&(r.has(n)||(r.add(n),t.push(n)))}return t}function x(e){return e=String(e||"").trim(),e?(e.startsWith("/")||(e="/"+e),e.endsWith("/")||(e+="/"),e):""}function k(e){return e=String(e||"").trim(),e?(e.startsWith("/")||(e="/"+e),e.length>1&&(e=e.replace(/\/+$/,"")),e):""}function W(e){return String(e||"").trim().replace(/^\/+|\/+$/g,"")}function v(e,t){let r=String(e||""),s=x(t);if(!s)return!1;let n=s.replace(/\/+$/,"");return r===n||r.startsWith(s)}function p(e,t){return e+(t?`?${t}`:"")}function _(e){return/\/[^/]+\.[a-z0-9]+$/i.test(String(e||""))}function R(e,t){let r=e.config.root||process.cwd(),s=String(t||"").replace(/^\/+/,"");return F.resolve(r,s)}function L(e,t){try{let r=R(e,t);return w.existsSync(r)&&w.statSync(r).isFile()}catch{return!1}}function D(e,t){for(let r of t||[])if(L(e,r))return r;return""}function z(e){return String(e||"").replace(/^\/+/,"").split("/")[0]||""}function T(e={}){let t=e.locale||{},r={...g.locale,...t},s=Array.isArray(e.localePrefixes)?e.localePrefixes:[],n=Array.isArray(r.prefixes)?r.prefixes:[],o=r.aliases||{},i=o&&typeof o=="object"?Object.keys(o):[],u=m([...n,...s,...i]).map(W).filter(Boolean);return{...r,defaultLang:r.defaultLang||"zh-CN",strategy:r.strategy||"prefix_except_default",prefixes:u}}function A(e,t){if(!t.locale||t.locale.enabled!==!0)return!1;let r=z(e);return r?(t.locale.prefixes||[]).includes(r):!1}function E(e,t){if(!A(e,t))return"";let s=String(e||"").replace(/^\/+/,"").split("/").slice(1).join("/");return s?"/"+s:"/"}function C(e){return e==="/vite-hmr"||e==="/__vite_ping"||e.startsWith("/@vite")||e.startsWith("/@id")||e.startsWith("/@fs")||e.startsWith("/__vite")||e==="/favicon.ico"}function V(e){let t=[];return e.srcRoot&&t.push(x(e.srcRoot)),e.viewsDir&&t.push(x(e.viewsDir)),t.push(...e.stripPrefixes||[]),t.push(...e.toSrcPrefixes||[]),t.push(...e.backendPrefixes||[]),t.push(...e.pageExcludePrefixes||[]),m(t).map(x).filter(Boolean)}function y(e,t){let r=String(e||"");return(t._pageExcludePrefixes||[]).some(s=>v(r,s))}function j(e,t){let r=[];if(r.push(`${t.viewsDir}${e}`),t.locale&&t.locale.fallbackToDefaultViews!==!1){let s=E(e,t);s&&s!==e&&r.push(`${t.viewsDir}${s}`)}return r}function I(e,t){let r=[],s=n=>{let o=String(n||"").trim();if(!o||o==="/"){r.push(`${t.viewsDir}/${t.htmlFallback}`);return}o.startsWith("/")||(o="/"+o),o=o.replace(/\/+$/,""),r.push(`${t.viewsDir}${o}/index.html`),r.push(`${t.viewsDir}${o}.html`)};if(s(e),t.locale&&t.locale.fallbackToDefaultViews!==!1){let n=E(e,t);n&&n!==e&&s(n)}return t.extensionlessFallbackToIndex&&r.push(`${t.viewsDir}/${t.htmlFallback}`),r}function B(e={}){let t=e.prefixes||e.toSrcPrefixes||[],r=e.strip||e.stripPrefixes||[],s=e.backendPrefixes||e.passthroughPrefixes||[],n=e.pageExcludePrefixes||e.excludePrefixes||[],o=T(e),i={...g,...e,srcRoot:k(e.srcRoot||g.srcRoot),viewsDir:k(e.viewsDir||g.viewsDir),toSrcPrefixes:m([...g.toSrcPrefixes,...t]).map(x),stripPrefixes:m([...g.stripPrefixes,...r]).map(x),backendPrefixes:m([...g.backendPrefixes,...s]).map(x),pageExcludePrefixes:m([...g.pageExcludePrefixes,...n]).map(x),locale:o};i._pageExcludePrefixes=V(i);let u=(...$)=>{i.debug&&console.log("[laybot-vite-dev]",...$)};return{name:"laybot-vite-dev",enforce:"pre",configureServer($){$.middlewares.use((a,N,f)=>{let d=a.url||"/",[l,h=""]=d.split("?");if((a.headers.upgrade||"").toLowerCase()==="websocket"||C(l))return f();for(let c of i.backendPrefixes)if(c&&v(l,c))return u(d,"=> backend passthrough"),f();if(l==="/"||l==="/index.html"){let c=`${i.viewsDir}/${i.htmlFallback}`;return a.url=p(c,h),u(d,"=>",a.url),f()}if(/\.html$/i.test(l)&&!y(l,i)){let c=j(l,i),b=D($,c)||c[0];return a.url=p(b,h),u(d,"=>",a.url),f()}for(let c of i.stripPrefixes)if(c&&v(l,c)){let P=x(c),b=l.slice(P.length-1),S=`${i.srcRoot}${b}`;return a.url=p(S,h),u(d,"=>",a.url),f()}for(let c of i.toSrcPrefixes)if(c&&v(l,c)){let P=`${i.srcRoot}${l}`;return a.url=p(P,h),u(d,"=>",a.url),f()}if(i.extensionlessRoutes===!0&&l!=="/"&&!_(l)&&!y(l,i)){let c=l.replace(/\/+$/,"")||"/",P=I(c,i),b=D($,P);if(b)return a.url=p(b,h),u(d,"=>",a.url),f();if(i.extensionlessFallbackToIndex){let S=`${i.viewsDir}/${i.htmlFallback}`;return a.url=p(S,h),u(d,"=>",a.url),f()}}return f()})}}}export{B as default};
|
package/package.json
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "laybot-vite-dev",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Vite dev rewrite plugin for LayBot/LarryMS MPA runtime loader",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./dist/index.js"
|
|
9
9
|
},
|
|
10
|
-
"files": [
|
|
11
|
-
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE"
|
|
14
|
+
],
|
|
15
|
+
"keywords": [
|
|
16
|
+
"vite",
|
|
17
|
+
"plugin",
|
|
18
|
+
"mpa",
|
|
19
|
+
"larryms",
|
|
20
|
+
"laybot"
|
|
21
|
+
],
|
|
12
22
|
"author": "larry",
|
|
13
23
|
"license": "MIT",
|
|
14
24
|
"peerDependencies": {
|