Skip to content

Commit 1d1e414

Browse files
authored
bugfix (#24)
1 parent c615441 commit 1d1e414

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

lib/utils.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,25 @@ const getAbsoluteUrl = (resolveDir, url) => {
4040
* @returns {string}
4141
*/
4242
const buildInjectCode = (injectToSelector = 'head', css, digest, { urlFullPathMap }) => {
43-
const placeholders = [];
43+
const patchedPlaceholders = [];
4444
const imports = Object.keys(urlFullPathMap)
4545
.map((placeholder) => {
46-
placeholders.push(placeholder);
47-
return `import ${placeholder} from '${urlFullPathMap[placeholder]}';`;
46+
// placeholder can start with number
47+
patchedPlaceholders.push('__' + placeholder);
48+
return `import __${placeholder} from '${urlFullPathMap[placeholder]}';`;
4849
})
4950
.join('\n');
5051
return `${imports}
5152
(function(){
5253
let css = \`${css}\`;
5354
${
54-
placeholders.length
55+
patchedPlaceholders.length
5556
? `
56-
const placeholders = \`${placeholders.join(',')}\`.split(',');
57-
const urls = [${placeholders.join(',')}];
57+
const placeholders = \`${patchedPlaceholders.join(',')}\`.split(',');
58+
const urls = [${patchedPlaceholders.join(',')}];
5859
placeholders.forEach(function(p, index) {
59-
css = css.replace(new RegExp(\`"\${p}"\`, 'g'), urls[index]);
60+
const originPlaceholder = p.replace(/^__/, '');
61+
css = css.replace(new RegExp(\`"\${originPlaceholder}"\`, 'g'), urls[index]);
6062
});
6163
`
6264
: ''

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "esbuild-css-modules-plugin",
3-
"version": "2.2.0",
3+
"version": "2.2.1",
44
"description": "A esbuild plugin to bundle css modules into js(x)/ts(x).",
55
"main": "index.js",
66
"keywords": [

0 commit comments

Comments
 (0)