webpack-typings-for-css
Version:
Webpack loader that generates TypeScript typings for CSS modules
2 lines (1 loc) • 2.56 kB
JavaScript
"use strict";var e=require("node:fs"),n=require("node:path"),t=require("camelcase");function r(e){const n={};return Object.entries(e).forEach((([e,r])=>{n[function(e){return/^[a-z][a-z0-9\-_]+/gi.test(e)?t(e,{locale:"en-US"}):e}(e)]=r})),n}var l={1:function(e,n,t,r,l){var o,a=e.lambda;return" '"+(null!=(o=a(e.strict(l,"key",{start:{line:7,column:7},end:{line:7,column:11}}),n))?o:"")+"': '"+(null!=(o=a(n,n))?o:"")+"',\n"},3:function(e,n,t,r,l){var o,a=e.lookupProperty||function(e,n){if(Object.prototype.hasOwnProperty.call(e,n))return e[n]};return"export type ClassName = (\n"+(null!=(o=a(t,"each").call(null!=n?n:e.nullContext||{},a(n,"exports"),{name:"each",hash:{},fn:e.program(4,l,0),inverse:e.noop,data:l,loc:{start:{line:13,column:0},end:{line:15,column:9}}}))?o:"")+");\n\n"},4:function(e,n,t,r,l){var o,a=e.lookupProperty||function(e,n){if(Object.prototype.hasOwnProperty.call(e,n))return e[n]};return" '"+(null!=(o=e.lambda(n,n))?o:"")+"'"+(null!=(o=a(t,"unless").call(null!=n?n:e.nullContext||{},a(l,"last"),{name:"unless",hash:{},fn:e.program(5,l,0),inverse:e.noop,data:l,loc:{start:{line:14,column:14},end:{line:14,column:44}}}))?o:"")+"\n"},5:function(e,n,t,r,l){return" |"},7:function(e,n,t,r,l){return"export type ClassName = string;\n\n"},compiler:[8,">= 4.3.0"],main:function(e,n,t,r,l){var o,a=null!=n?n:e.nullContext||{},s=e.lookupProperty||function(e,n){if(Object.prototype.hasOwnProperty.call(e,n))return e[n]};return"// *** This file is automatically generated - Do not edit! ***\n/* tslint:disable */\n/* eslint-disable */\n\ndeclare const styles = {\n"+(null!=(o=s(t,"each").call(a,s(n,"exports"),{name:"each",hash:{},fn:e.program(1,l,0),inverse:e.noop,data:l,loc:{start:{line:6,column:0},end:{line:8,column:9}}}))?o:"")+"} as const;\n\n"+(null!=(o=s(t,"if").call(a,s(n,"exportType"),{name:"if",hash:{},fn:e.program(3,l,0),inverse:e.program(7,l,0),data:l,loc:{start:{line:11,column:0},end:{line:21,column:7}}}))?o:"")+"export default styles;"},useData:!0};const o=require("handlebars/runtime").template(l);module.exports=function(t){this.cacheable&&this.cacheable();const l=/___CSS_LOADER_EXPORT___\.locals = (\{[\S\s]*\});/gm.exec(t);if(l&&l.length){const a=this.getOptions(),s=String(l[1]).replace(/`/g,'"'),c=JSON.parse(s),u=a&&!0===a.exportType,i=r(c),p=n.extname(this.resourcePath),m=this.resourcePath.replace(`${p}`,`${p}.d.ts`),h=o({exports:i,exportType:u});return e.writeFileSync(m,h),function(e,n){return e.replace(/exports\.locals = \{[\S\s]*\};/gm,`exports.locals = ${JSON.stringify(n,null,3)};`)}(t,i)}return t};