Skip to content

Commit

Permalink
v3.1.2: fix issue#74
Browse files Browse the repository at this point in the history
  • Loading branch information
indooorsman committed Apr 25, 2024
1 parent d740ccb commit 2ca1e81
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## V3.1.2
- fix [issue#74](https://github.com/indooorsman/esbuild-css-modules-plugin/issues/74)

## V3.1.1
- fix build with `bundle: true` & `splitting: true` & multiple entrypoints

Expand Down
13 changes: 7 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,14 @@ export const setup = (build, _options) => {
readFile(fullJsPath, { encoding: 'utf8' })
])
.then(([css, js]) => {
const cssContent = simpleMinifyCss(css, patchedBuild.esbuild);
const digest = genDigest(c, buildId);
const newJs = js
.replace(
contentPlaceholder,
JSON.stringify(simpleMinifyCss(css, patchedBuild.esbuild))
)
.replace(digestPlaceholder, JSON.stringify(genDigest(c, buildId)));
return newJs;
.replaceAll(contentPlaceholder, `globalThis['__css-content-${digest}__']`)
.replaceAll(digestPlaceholder, `globalThis['__css-digest-${digest}__']`);
return `globalThis['__css-content-${digest}__']=${JSON.stringify(
cssContent
)};globalThis['__css-digest-${digest}__']=${JSON.stringify(digest)};\n${newJs}`;
})
.then((newJs) => writeFile(fullJsPath, newJs, { encoding: 'utf8' }));
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "esbuild-css-modules-plugin",
"version": "3.1.1",
"version": "3.1.2",
"description": "A esbuild plugin to bundle css modules into js(x)/ts(x), based on extremely fast [Lightning CSS](https://lightningcss.dev/)",
"main": "./index.cjs",
"module": "./index.js",
Expand Down
11 changes: 8 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import cssModulesPlugin from '../index.js';
emitDeclarationFile: true
})
],
metafile: true,
logLevel: 'debug'
});
console.log('[test][esbuild:bundle:inject] done, please check `test/dist/bundle-inject`', '\n');
Expand All @@ -39,6 +40,7 @@ import cssModulesPlugin from '../index.js';
external: ['react', 'react-dom'],
outdir: './dist/bundle-custom-inject',
write: true,
metafile: true,
loader: {
'.jpg': 'dataurl'
},
Expand Down Expand Up @@ -86,7 +88,8 @@ import cssModulesPlugin from '../index.js';
filter: /\.css$/i
})
],
logLevel: 'debug'
logLevel: 'debug',
metafile: true
});
console.log('[test][esbuild:bundle:custom:filter] done, please check `test/dist/bundle-custom-filter`', '\n');

Expand All @@ -112,7 +115,8 @@ import cssModulesPlugin from '../index.js';
emitDeclarationFile: true
})
],
logLevel: 'debug'
logLevel: 'debug',
metafile: true
});
console.log('[test][esbuild:bundle:no:inject] done, please check `test/dist/bundle-no-inject`', '\n');

Expand Down Expand Up @@ -143,7 +147,8 @@ import cssModulesPlugin from '../index.js';
inject: '#my-styles-container'
})
],
logLevel: 'debug'
logLevel: 'debug',
metafile: true
};

await esbuild.build(buildOptions);
Expand Down

0 comments on commit 2ca1e81

Please sign in to comment.