bun-lightningcss
Advanced tools
Comparing version 0.0.2 to 0.0.3
// @bun | ||
import{join as y} from"node:path";import D from"browserslist";import{browserslistToTargets as B,transform as W} from"lightningcss";function T(X={}){return{name:"bun-lightningcss",setup({onLoad:K,onResolve:Y,config:Z}){const M={minify:!0,sourceMap:!0,cssModules:!0,projectRoot:y(process.cwd(),Z.outdir||"dist")},{browserslist:_,...S}=X??{},U=B(D(_));Y({filter:/^__style_helper__$/},(I)=>{return{path:I.path,namespace:"style-helper"}}),K({filter:/.*/,namespace:"style-helper"},async()=>{return{contents:` | ||
import{join as y} from"node:path";import B from"browserslist";import{browserslistToTargets as D,transform as V} from"lightningcss";function E(W={}){return{name:"bun-lightningcss",setup({onLoad:J,onResolve:X,config:Y}){const K={minify:!0,sourceMap:!0,cssModules:!0,projectRoot:y(process.cwd(),Y.outdir||"dist")},{browserslist:Z,...Q}=W??{},S=D(B(Z));X({filter:/^__style_helper__$/},(_)=>{return{path:_.path,namespace:"style-helper"}}),J({filter:/.*/,namespace:"style-helper"},async()=>{return{contents:` | ||
export function injectStyle(text) { | ||
if (typeof document !== 'undefined') { | ||
const lightningcssStyleTag = document.getElementById('bun_lightningcss') | ||
if (lightningcssStyleTag) { | ||
const node = document.createTextNode(text) | ||
lightningcssStyleTag.appendChild(node) | ||
return | ||
} | ||
var style = document.createElement('style') | ||
style.id = 'bun_lightningcss' | ||
var node = document.createTextNode(text) | ||
@@ -11,9 +20,9 @@ style.appendChild(node) | ||
} | ||
`,loader:"js"}});const F=JSON.stringify,V=(I)=>F(I).slice(1,-1);if(M.cssModules)K({filter:/\.module\.css$/},async({path:I})=>{const P=await Bun.file(I).arrayBuffer(),{code:Q,exports:j={}}=W({filename:I,code:P,...M,targets:U,...S});let k="";const G=new Map,v=(A)=>{if(G.has(A))return G.get(A);const z=`dependency_${G.size}`;return k=`import ${z} from ${F(A)}\n${k}`,G.set(A,z),z};k+="import { injectStyle } from \'__style_helper__\'\n",k+=`injectStyle(${F(Q.toString())})\n`,k+="export default {";for(let[A,z]of Object.entries(j)){let H=`"${V(z.name)}`;if(z.composes)for(let J of z.composes)switch(J.type){case"local":case"global":H+=` ${V(J.name)}`;break;case"dependency":H+=` " + ${v(J.specifier)}[${F(J.name)}] + "`;break}H+='"',k+=`${JSON.stringify(A)}:${H},`}return k+="}",k+="\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==",{contents:k,loader:"js"}});K({filter:/^.*\.css(?!\.module\.css)$/},async({path:I})=>{const P=await Bun.file(I).arrayBuffer(),{code:Q}=W({filename:I,code:P,...M,targets:U,...S,cssModules:!1});return{contents:` | ||
`,loader:"js"}});const F=JSON.stringify,U=(_)=>F(_).slice(1,-1);if(K.cssModules)J({filter:/\.module\.css$/},async({path:_})=>{const M=await Bun.file(_).arrayBuffer(),{code:P,exports:j={}}=V({filename:_,code:M,...K,targets:S,...Q});let k="";const G=new Map,v=(A)=>{if(G.has(A))return G.get(A);const z=`dependency_${G.size}`;return k=`import ${z} from ${F(A)}\n${k}`,G.set(A,z),z};k+="import { injectStyle } from \'__style_helper__\'\n",k+=`injectStyle(${F(P.toString())})\n`,k+="export default {";for(let[A,z]of Object.entries(j)){let H=`"${U(z.name)}`;if(z.composes)for(let I of z.composes)switch(I.type){case"local":case"global":H+=` ${U(I.name)}`;break;case"dependency":H+=` " + ${v(I.specifier)}[${F(I.name)}] + "`;break}H+='"',k+=`${JSON.stringify(A)}:${H},`}return k+="}",k+="\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==",{contents:k,loader:"js"}});J({filter:/^.*\.css(?!\.module\.css)$/},async({path:_})=>{const M=await Bun.file(_).arrayBuffer(),{code:P}=V({filename:_,code:M,...K,targets:S,...Q,cssModules:!1});return{contents:` | ||
import { injectStyle } from '__style_helper__' | ||
injectStyle(${F(Q.toString())}) | ||
injectStyle(${F(P.toString())}) | ||
export default {} | ||
`,loader:"js"}})}}}export{T as default}; | ||
`,loader:"js"}})}}}export{E as default}; | ||
//# debugId=7BD0B2774056041264756e2164756e21 | ||
//# debugId=BC5E6E0ECD54FD6364756e2164756e21 |
{ | ||
"name": "bun-lightningcss", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"author": "Robert Soriano <sorianorobertc@gmail.com>", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -34,3 +34,12 @@ import { join } from 'node:path' | ||
if (typeof document !== 'undefined') { | ||
const lightningcssStyleTag = document.getElementById('bun_lightningcss') | ||
if (lightningcssStyleTag) { | ||
const node = document.createTextNode(text) | ||
lightningcssStyleTag.appendChild(node) | ||
return | ||
} | ||
var style = document.createElement('style') | ||
style.id = 'bun_lightningcss' | ||
var node = document.createTextNode(text) | ||
@@ -37,0 +46,0 @@ style.appendChild(node) |
Sorry, the diff of this file is not supported yet
210147
361