esbuild-css-modules-plugin
Advanced tools
Comparing version 2.1.2 to 2.1.3
34
index.js
@@ -18,3 +18,7 @@ const path = require('path'); | ||
const getAbsoluteUrl = (resolveDir, url) => { | ||
return path.resolve(resolveDir, url.replace(/\"/g, '').replace(/\'/g, '')); | ||
const pureUrl = url.replace(/\"/g, '').replace(/\'/g, ''); | ||
if (path.isAbsolute(pureUrl) || pureUrl.startsWith('http')) { | ||
return pureUrl; | ||
} | ||
return path.resolve(resolveDir, pureUrl); | ||
}; | ||
@@ -24,6 +28,8 @@ | ||
const resolveDir = path.dirname(cssFullPath); | ||
const cssContent = await readFile(cssFullPath); | ||
const transformConfig = { | ||
filename: path.basename(cssFullPath), | ||
code: cssContent, | ||
/** | ||
* @type {import('@parcel/css').BundleOptions} | ||
*/ | ||
const bundleConfig = { | ||
filename: cssFullPath, | ||
minify: false, | ||
@@ -34,3 +40,4 @@ sourceMap: true, | ||
}; | ||
const { code, exports, map, dependencies } = cssHandler.transform(transformConfig); | ||
const { code, exports = {}, map, dependencies = [] } = cssHandler.bundle(bundleConfig); | ||
const cssModulesJSON = {}; | ||
@@ -40,7 +47,6 @@ Object.keys(exports).forEach((originClass) => { | ||
}); | ||
const classNames = JSON.stringify(cssModulesJSON); | ||
const jsContent = ` | ||
export default ${classNames}; | ||
`; | ||
const urls = dependencies?.filter((d) => d.type === 'url') ?? []; | ||
const classNames = JSON.stringify(cssModulesJSON, null, 2); | ||
const urls = dependencies.filter((d) => d.type === 'url'); | ||
let finalCssContent = code.toString('utf-8'); | ||
@@ -53,2 +59,5 @@ urls.forEach(({ url, placeholder }) => { | ||
}); | ||
const jsContent = `export default ${classNames};`; | ||
if (map) { | ||
@@ -163,3 +172,4 @@ finalCssContent += `\n/*# sourceMappingURL=data:application/json;base64,${map.toString( | ||
return { | ||
contents: jsFileContent | ||
contents: jsFileContent, | ||
loader: 'js' | ||
}; | ||
@@ -166,0 +176,0 @@ }); |
{ | ||
"name": "esbuild-css-modules-plugin", | ||
"version": "2.1.2", | ||
"version": "2.1.3", | ||
"description": "A esbuild plugin to bundle css modules into js(x)/ts(x).", | ||
@@ -21,13 +21,13 @@ "main": "index.js", | ||
}, | ||
"devDependencies": { | ||
"esbuild": "^0.14.11" | ||
"peerDependencies": { | ||
"esbuild": "^0.14.21" | ||
}, | ||
"dependencies": { | ||
"@parcel/css": "^1.0.1", | ||
"@parcel/css": "^1.3.1", | ||
"fs-extra": "^9.1.0", | ||
"lodash": "^4.17.21", | ||
"postcss": "^8.2.7", | ||
"postcss-modules": "^4.0.0", | ||
"postcss": "^8.4.6", | ||
"postcss-modules": "^4.3.0", | ||
"tmp": "^0.2.1" | ||
} | ||
} |
import React from 'react'; | ||
import styles, * as appCssModules from '../styles/app.modules.css'; | ||
import styles2, * as h from '../styles/deep/styles/hello.modules.css'; | ||
@@ -8,3 +7,3 @@ export const HelloWorld = () => ( | ||
<h3 className={styles.helloWorld}>Hello World!</h3> | ||
<p className={styles2.helloText}>hi...</p> | ||
<p className={styles.helloText}>hi...</p> | ||
<pre> | ||
@@ -14,8 +13,5 @@ <code>${appCssModules?.digest ?? '// n/a'}</code> | ||
<pre> | ||
<code>${h?.digest ?? '// n/a'}</code> | ||
<code>${appCssModules?.css ?? '// n/a'}</code> | ||
</pre> | ||
<pre> | ||
<code>${h?.css ?? '// n/a'}</code> | ||
</pre> | ||
</> | ||
); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33799
0
13
378
7
+ Added@esbuild/linux-loong64@0.14.54(transitive)
+ Addedesbuild@0.14.54(transitive)
+ Addedesbuild-android-64@0.14.54(transitive)
+ Addedesbuild-android-arm64@0.14.54(transitive)
+ Addedesbuild-darwin-64@0.14.54(transitive)
+ Addedesbuild-darwin-arm64@0.14.54(transitive)
+ Addedesbuild-freebsd-64@0.14.54(transitive)
+ Addedesbuild-freebsd-arm64@0.14.54(transitive)
+ Addedesbuild-linux-32@0.14.54(transitive)
+ Addedesbuild-linux-64@0.14.54(transitive)
+ Addedesbuild-linux-arm@0.14.54(transitive)
+ Addedesbuild-linux-arm64@0.14.54(transitive)
+ Addedesbuild-linux-mips64le@0.14.54(transitive)
+ Addedesbuild-linux-ppc64le@0.14.54(transitive)
+ Addedesbuild-linux-riscv64@0.14.54(transitive)
+ Addedesbuild-linux-s390x@0.14.54(transitive)
+ Addedesbuild-netbsd-64@0.14.54(transitive)
+ Addedesbuild-openbsd-64@0.14.54(transitive)
+ Addedesbuild-sunos-64@0.14.54(transitive)
+ Addedesbuild-windows-32@0.14.54(transitive)
+ Addedesbuild-windows-64@0.14.54(transitive)
+ Addedesbuild-windows-arm64@0.14.54(transitive)
Updated@parcel/css@^1.3.1
Updatedpostcss@^8.4.6
Updatedpostcss-modules@^4.3.0