adastra-plugin
Advanced tools
Comparing version
import { Plugin } from 'vite'; | ||
type PluginAdastraOptions = { | ||
interface PluginAdastraOptions { | ||
root?: string; | ||
sourceDir?: string; | ||
entrypointsDir?: string; | ||
additionalEntrypoints?: string[]; | ||
hash?: boolean; | ||
minify?: boolean; | ||
sourcemap?: boolean; | ||
}; | ||
} | ||
@@ -13,0 +11,0 @@ declare const _default: (options?: PluginAdastraOptions) => Plugin[]; |
@@ -1,14 +0,14 @@ | ||
import h from"path";import{normalizePath as U}from"vite";var A=e=>{let s=typeof e.root<"u"?h.normalize(e.root):"./",i=typeof e.sourceDir<"u"?h.normalize(e.sourceDir):"src",r=typeof e.entrypointsDir<"u"?h.normalize(e.entrypointsDir):U(h.join(i)),t=typeof e.additionalEntrypoints<"u"?e.additionalEntrypoints:[],n=typeof e.hash<"u",a=typeof e.minify>"u",p=typeof e.sourcemap>"u";return{root:s,sourceDir:i,entrypointsDir:r,additionalEntrypoints:t,hash:n,minify:a,sourcemap:p}};import g from"path";import w from"fast-glob";import W from"debug";import{mergeConfig as B,normalizePath as J}from"vite";var K=W("adastra:config"),I=e=>({name:"adastra:config",config(s,i){let r=s.server?.host??"localhost",t=s.server?.port??5173,n=s.server?.https,p=`${n===!0?"https:":"http:"}//${r}:${t}`,o=n===!0?"wss":"ws",l=w.sync(J(g.join(e.entrypointsDir,e.entrypointsDir==="src"?"/*":"**/*")),{onlyFiles:!0});e.additionalEntrypoints.forEach(u=>{l=l.concat(w.sync(u,{onlyFiles:!0}))});let S={chunkFileNames:`[name]${e.hash?".[hash]":""}.js`,entryFileNames:`[name]${e.hash?".[hash]":""}.js`,assetFileNames:`[name]${e.hash?".[hash]":""}.[ext]`},d={base:"./",envPrefix:["VITE_","PUBLIC_"],css:{devSourcemap:e.sourcemap},publicDir:g.join(e.sourceDir,"public"),build:{outDir:g.join(e.root,"assets"),modulePreload:{polyfill:!0},assetsDir:"",rollupOptions:{input:l,output:S},manifest:"adastra.manifest.json",minify:e.minify},resolve:{alias:{"~":g.resolve(e.sourceDir),"@":g.resolve(e.sourceDir)}},server:{host:r,https:n,port:t,origin:p,strictPort:!0,hmr:{host:r,port:t,protocol:o},watch:{ignored:["assets/*","snippets/adastra.liquid"]}}};return K(d),B(d,s)}});import x from"fs";import f from"path";import Y from"debug";import{normalizePath as L}from"vite";import*as k from"vite";var G=k.version?.startsWith("3.");var N=["css","less","sass","scss","styl","stylus","pcss","postcss"],F=["jsx","tsx"],X=new RegExp(`\\.(${N.join("|")})(\\?.+)?$`),O="@vite/client",z="@react-refresh";import V from"path";import{normalizePath as Q}from"vite";var y=`{% # theme-check-disable %} | ||
`,_=`{% comment %} | ||
import H from"path";var R=t=>{let s=t.root??"./",r=t.sourceDir??"src",e=H.join(r,t.entrypointsDir??"entrypoints"),i=t.hash??!1,o=t.minify??!0;return{root:s,sourceDir:r,entrypointsDir:e,hash:i,minify:o}};import l from"path";import M from"fast-glob";import U from"debug";import{mergeConfig as W,normalizePath as B}from"vite";var J=U("adastra-plugin:config"),A=t=>({name:"adastra-plugin-config",config(s){let r=s.server?.host??"localhost",e=s.server?.port??5173,i=s.server?.https,c=`${i===!0?"https:":"http:"}//${r}:${e}`,n=i===!0?"wss":"ws",a=M.sync(B(l.join(t.entrypointsDir,"**/*")),{onlyFiles:!0}),d={base:"./",envPrefix:["VITE_","PUBLIC_","ADASTRA_"],publicDir:!1,build:{outDir:l.join(t.root,"assets"),modulePreload:{polyfill:!0},assetsDir:"",rollupOptions:{input:a,output:{chunkFileNames:`[name]${t.hash?".[hash]":""}.js`,entryFileNames:g=>`${g.name.replace("entry.","")}${t.hash?".[hash]":""}.js`,assetFileNames:`[name]${t.hash?".[hash]":""}.[ext]`}},manifest:"adastra.manifest.json",minify:t.minify},resolve:{alias:{"~":l.resolve(t.sourceDir),"@":l.resolve(t.sourceDir)}},server:{host:r,https:i,port:e,origin:c,strictPort:!0,hmr:{host:r,port:e,protocol:n},watch:{ignored:[l.join(t.root,"assets/*"),l.join(t.root,"snippets/adastra.liquid")]}}};return J(d),W(d,s)}});import T from"fs";import x from"path";import V from"debug";import{normalizePath as Q}from"vite";import*as j from"vite";var K=j.version.startsWith("3.");var P=["css","less","sass","scss","styl","stylus","pcss","postcss"],b=["jsx","tsx"],D=new RegExp(`\\.(${P.join("|")})(\\?.+)?$`),$="@vite/client",w="@react-refresh";import z from"path";import{normalizePath as G}from"vite";var m=`{% # theme-check-disable %} | ||
`,u=`{% comment %} | ||
IMPORTANT: This snippet is automatically generated by Adastra. | ||
Do not attempt to modify this file directly, as any changes will be overwritten by the next build. | ||
{% endcomment %} | ||
`,T=(e,s)=>{let i=[];return e.forEach(r=>{typeof r.find=="string"&&i.push([r.find,Q(V.relative(s,r.replacement))])}),`{% assign path = adastra | ${i.map(([r,t])=>`replace: '${r}/', '${t}/'`).join(" | ")} %} | ||
`},E=(e,s,i=!1)=>`{% ${i?"":"els"}if ${e.map(r=>`path == "${r}"`).join(" or ")} %} | ||
${s}`,v=e=>`<link rel="modulepreload" href="{{ '${e}' | asset_url | split: '?' | first }}" crossorigin="anonymous">`,R=e=>`<script src="{{ '${e}' | asset_url | split: '?' | first }}" type="module" crossorigin="anonymous"><\/script>`,m=e=>`{{ '${e}' | asset_url | split: '?' | first | stylesheet_tag: preload: preload }}`,D=(e="http://localhost:5173",s="src",i="")=>`{% liquid | ||
`,h=(t,s)=>{let r=[];return t.forEach(e=>{typeof e.find=="string"&&r.push([e.find,G(z.relative(s,e.replacement))])}),`{% assign path = adastra | ${r.map(([e,i])=>`replace: '${e}/', '${i}/'`).join(" | ")} %} | ||
`},y=(t,s,r=!1)=>`{% ${r?"":"els"}if ${t.map(e=>`path == "${e}"`).join(" or ")} %} | ||
${s}`,_=t=>`<link rel="modulepreload" href="{{ '${t}' | asset_url | split: '?' | first }}" crossorigin="anonymous">`,O=t=>`<script src="{{ '${t}' | asset_url | split: '?' | first }}" type="module" crossorigin="anonymous"></script>`,f=t=>`{{ '${t}' | asset_url | split: '?' | first | stylesheet_tag: preload: preload }}`,C=(t,s)=>`{% liquid | ||
assign path_prefix = path | slice: 0 | ||
if path_prefix == '/' | ||
assign file_url_prefix = '${e}' | ||
assign file_url_prefix = '${t}' | ||
else | ||
assign file_url_prefix = '${e}/${s}/' | ||
assign file_url_prefix = '${t}/${s}/' | ||
endif | ||
@@ -22,4 +22,4 @@ | ||
assign css_extensions = '${N.join("|")}' | split: '|' | ||
assign jsx_extensions = '${F.join("|")}' | split: '|' | ||
assign css_extensions = '${P.join("|")}' | split: '|' | ||
assign jsx_extensions = '${b.join("|")}' | split: '|' | ||
assign is_css = false | ||
@@ -36,4 +36,3 @@ assign is_jsx = false | ||
assign modules_path = '${i}' | ||
if file_extension == blank and modules_path != blank and file_url contains modules_path | ||
if file_extension == blank | ||
assign file_url = file_url | append: '/' | append: file_name | ||
@@ -45,3 +44,3 @@ endif | ||
<script type="module"> | ||
import RefreshRuntime from "${e}/${z}" | ||
import RefreshRuntime from "${t}/${w}" | ||
RefreshRuntime.injectIntoGlobalHook(window) | ||
@@ -51,6 +50,6 @@ window.$RefreshReg$ = () => {} | ||
window.__vite_plugin_react_preamble_installed__ = true | ||
<\/script> | ||
</script> | ||
{% endif %} | ||
<script src="${e}/${O}" type="module"><\/script> | ||
<script src="${t}/${$}" type="module"></script> | ||
@@ -60,8 +59,8 @@ {% if is_css %} | ||
{% else %} | ||
<script src="{{ file_url }}" type="module" crossorigin="anonymous"><\/script> | ||
<script src="{{ file_url }}" type="module" crossorigin="anonymous"></script> | ||
{% endif %} | ||
`;var Z=Y("adastra:liquid"),q=e=>{let s,i="",r=f.resolve(e.root,"snippets/adastra.liquid");return{name:"adastra:liquid",enforce:"post",configResolved(t){s=t;let n=s.resolve.alias.find(a=>a.find==="@modules");n!=null&&(i=L(f.relative(e.entrypointsDir,n.replacement)))},configureServer({config:t}){let n=t.server?.https===!0?"https:":"http:",a=typeof t.server?.host=="string"?t.server.host:"localhost",p=typeof t.server?.port<"u"?t.server.port:5173,o=typeof t.server?.origin=="string"?t.server.origin:`${n}//${a}:${p}`;Z({assetHost:o});let l=y+_+T(t.resolve.alias,e.entrypointsDir)+D(o,e.entrypointsDir,i);x.writeFileSync(r,l)},closeBundle(){let t=f.resolve(e.root,"assets/adastra.manifest.json");if(!x.existsSync(t))return;let n=[],a=JSON.parse(x.readFileSync(t,"utf8"));Object.keys(a).forEach(o=>{let{file:l,isEntry:S,css:d,imports:u}=a[o],H=f.extname(o);if(S===!0){let P=L(f.relative(e.entrypointsDir,o)),b=[`/${o}`,P],c=[];H.match(X)!==null?c.push(m(l)):(c.push(v(l)),c.push(R(l)),typeof d<"u"&&d.length>0&&d.forEach($=>{c.push(m($))}),typeof u<"u"&&u.length>0&&u.forEach($=>{let j=a[$],{css:C}=j;c.push(v(j.file)),typeof C<"u"&&C.length>0&&C.forEach(M=>{c.push(m(M))})}),i!==""&&!f.relative(i,P).includes("..")&&b.push(f.dirname(P))),n.push(E(b,c.join(` | ||
`),n.length===0))}o==="style.css"&&!s.build.cssCodeSplit&&n.push(E([o],m(l),!1))});let p=y+_+T(s.resolve.alias,e.entrypointsDir)+n.join(` | ||
`;var Y=V("adastra-plugin:liquid"),I=t=>{let s,r=x.resolve(t.root,"snippets/adastra.liquid");return{name:"adastra-plugin-liquid",enforce:"post",configResolved(e){s=e},configureServer({config:e}){let i=e.server?.https===!0?"https:":"http:",o=typeof e.server?.host=="string"?e.server.host:"localhost",c=typeof e.server?.port<"u"?e.server.port:5173,n=typeof e.server?.origin=="string"?e.server.origin:`${i}//${o}:${c}`;Y({assetHost:n});let a=m+u+h(e.resolve.alias,t.entrypointsDir)+C(n,t.entrypointsDir);T.writeFileSync(r,a)},closeBundle(){let e=x.resolve(t.root,"assets/adastra.manifest.json");if(!T.existsSync(e))return;let i=[],o=JSON.parse(T.readFileSync(e,"utf8"));Object.keys(o).forEach(n=>{let{file:a,isEntry:d,css:g,imports:E}=o[n],F=x.extname(n);if(d===!0){let X=Q(x.relative(t.entrypointsDir,n)),L=[`/${n}`,X],p=[];F.match(D)!==null?p.push(f(a)):(p.push(_(a)),p.push(O(a)),typeof g<"u"&&g.length>0&&g.forEach(S=>{p.push(f(S))}),typeof E<"u"&&E.length>0&&E.forEach(S=>{let N=o[S],{css:v}=N;p.push(_(N.file)),typeof v<"u"&&v.length>0&&v.forEach(q=>{p.push(f(q))})})),i.push(y(L,p.join(` | ||
`),i.length===0))}n==="style.css"&&!s.build.cssCodeSplit&&i.push(y([n],f(a),!1))});let c=m+u+h(s.resolve.alias,t.entrypointsDir)+i.join(` | ||
`)+` | ||
{% endif %} | ||
`;x.writeFileSync(r,p)}}};var Le=(e={})=>{let s=A(e);return[I(s),q(s)]};export{Le as default}; | ||
`;T.writeFileSync(r,c)}}};var Z={},k=Z;var qt=(t=k)=>{let s=R(t);return[A(s),I(s)]};export{qt as default}; |
{ | ||
"name": "adastra-plugin", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"author": "Blanklob", | ||
@@ -16,3 +16,3 @@ "license": "MIT", | ||
"fast-glob": "^3.2.11", | ||
"adastra-branding": "0.1.0" | ||
"adastra-branding": "0.1.1" | ||
}, | ||
@@ -23,3 +23,3 @@ "devDependencies": { | ||
"adastra-tsconfig": "0.1.0", | ||
"eslint-config-adastra": "0.1.0" | ||
"eslint-config-adastra": "0.1.1" | ||
}, | ||
@@ -43,4 +43,4 @@ "peerDependencies": { | ||
"watch": "tsup src/index.ts --format cjs,esm --dts --watch", | ||
"lint": "eslint", | ||
"lint:fix": "eslint --fix", | ||
"lint": "eslint .", | ||
"lint:fix": "eslint . --fix", | ||
"lint:types": "tsc --noEmit", | ||
@@ -47,0 +47,0 @@ "test": "vitest run", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
19622
-9.76%208
-4.59%+ Added
- Removed
Updated