Skip to content

Commit 7f138b5

Browse files
committed
v2.2.8
1 parent fb48e03 commit 7f138b5

File tree

5 files changed

+31
-9
lines changed

5 files changed

+31
-9
lines changed

changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
## V2.2.7
1+
## V2.2.8
22
- **[v2]** refine some logs
33
- **[v2]** make hash of outputs stable
4+
- **[v2]** support `entryPoints` as object
45

56
## V2.2.6
67
- **[v2]** refine some logs

lib/plugin.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,18 @@ const onEnd = async (build, options, result) => {
199199

200200
if (options.inject === true || typeof options.inject === 'string') {
201201
const cssContents = [];
202-
const entries = build.initialOptions.entryPoints.map((entry) => path.resolve(buildRoot, entry));
202+
const { entryPoints } = build.initialOptions;
203+
let entriesArray = [];
204+
if (Array.isArray(entryPoints)) {
205+
entriesArray = [...entryPoints];
206+
} else {
207+
Object.keys(entryPoints)
208+
.sort()
209+
.forEach((k) => {
210+
entriesArray.push(entryPoints[k]);
211+
});
212+
}
213+
const entries = entriesArray.map((p) => (path.isAbsolute(p) ? p : path.resolve(buildRoot, p)));
203214
log('entries:', entries);
204215
let injectTo = null;
205216
Object.keys(result.metafile?.outputs ?? []).forEach((f) => {

lib/utils.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,20 @@ const getRelativePath = (build, to) => {
108108
const getBuildId = (build) => {
109109
const { entryPoints } = build.initialOptions;
110110
const buildRoot = getRootDir(build);
111-
const entryPaths = entryPoints.map((p) => {
112-
return path.isAbsolute(p) ? p : path.resolve(buildRoot, p);
113-
});
114-
const entryContents = entryPaths
111+
let entries = [];
112+
if (Array.isArray(entryPoints)) {
113+
entries = [...entryPoints];
114+
} else {
115+
Object.keys(entryPoints)
116+
.sort()
117+
.forEach((k) => {
118+
entries.push(entryPoints[k]);
119+
});
120+
}
121+
const entryContents = entries
115122
.map((p) => {
116-
return readFileSync(p, { encoding: 'utf8' });
123+
const absPath = path.isAbsolute(p) ? p : path.resolve(buildRoot, p);
124+
return readFileSync(absPath, { encoding: 'utf8' });
117125
})
118126
.join('');
119127
return createHash('sha256').update(entryContents).digest('hex');

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.7",
3+
"version": "2.2.8",
44
"description": "A esbuild plugin to bundle css modules into js(x)/ts(x).",
55
"main": "index.js",
66
"keywords": [

test/test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ fse.emptyDirSync('./dist');
7373
console.log('[test][esbuild:no-bundle] done, please check `test/dist/no-bundle`', '\n');
7474

7575
await esbuild.build({
76-
entryPoints: ['app.jsx'],
76+
entryPoints: {
77+
['custom-entry-name']: 'app.jsx'
78+
},
7779
entryNames: '[name]-[hash]',
7880
format: 'esm',
7981
target: ['es2020'],

0 commit comments

Comments
 (0)