esbuild-css-modules-plugin
Advanced tools
Comparing version 2.6.0 to 2.6.1-beta.1
@@ -51,2 +51,3 @@ import type { OnLoadResult, Plugin, PluginBuild } from 'esbuild'; | ||
v2?: boolean; | ||
generateTsFile?: boolean; | ||
v2CssModulesOption?: { | ||
@@ -53,0 +54,0 @@ /** |
@@ -31,3 +31,3 @@ const path = require('path'); | ||
const cssFileName = path.basename(fullPath); // e.g. xxx.module.css?esbuild-css-modules-plugin-building | ||
const { buildId, relative, packageVersion } = build.context; | ||
const { buildId, relative, packageVersion, log } = build.context; | ||
const resolveDir = path.dirname(fullPath); | ||
@@ -39,2 +39,3 @@ const classPrefix = | ||
const cssModulesOption = options.v2CssModulesOption || {}; | ||
const genTs = !!options.generateTsFile; | ||
@@ -67,3 +68,3 @@ /** | ||
if (options.usePascalCase) { | ||
name = upperFirst(name) | ||
name = upperFirst(name); | ||
} | ||
@@ -103,2 +104,3 @@ | ||
const namedExportsTs = []; | ||
const namedExportStatements = Object.entries(cssModulesJSON) | ||
@@ -111,3 +113,5 @@ .map(([camelCaseClassName, className]) => { | ||
} | ||
return `export const ${camelCaseClassName} = "${className}";`; | ||
const line = `export const ${camelCaseClassName} = "${className}"`; | ||
genTs && namedExportsTs.push(`${line} as const;`); | ||
return `${line};`; | ||
}) | ||
@@ -118,2 +122,9 @@ .join('\n'); | ||
if (genTs) { | ||
const ts = `export default ${classNamesMapString} as const;\n${namedExportsTs.join('\n')}\n`; | ||
const tsPath = `${fullPath.replace(/\?.+$/, '')}.ts`; | ||
log(tsPath, ts); | ||
await writeFile(tsPath, ts, { encoding: 'utf-8' }); | ||
} | ||
return { | ||
@@ -224,3 +235,3 @@ js, | ||
const { js, resolveDir, css, exports, originCss } = await buildCssModulesJs({ | ||
const { js, ts, resolveDir, css, exports, originCss } = await buildCssModulesJs({ | ||
fullPath: absPath, | ||
@@ -227,0 +238,0 @@ options, |
{ | ||
"name": "esbuild-css-modules-plugin", | ||
"version": "2.6.0", | ||
"version": "2.6.1-beta.1", | ||
"description": "A esbuild plugin to bundle css modules into js(x)/ts(x).", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
38153
1007
2