Skip to content

Commit c7988de

Browse files
committed
Support css content in esbuild plugin
1 parent 2d063b9 commit c7988de

File tree

6 files changed

+23
-8
lines changed

6 files changed

+23
-8
lines changed

packages/esbuild/index.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,20 @@ function getFiles(buildResult, check) {
2323
let outputs = buildResult.metafile.outputs
2424

2525
for (let key in outputs) {
26-
let outputEntryName = parse(key).name
26+
let outputEntryName = parse(key).base
2727
outputs[outputEntryName] = outputs[key]
2828
outputs[outputEntryName].path = resolve(key)
2929
delete outputs[key]
3030
}
3131

3232
if (check.entry) {
33-
for (let i of check.entry) {
34-
if (outputs[i]) {
35-
entries[i] = outputs[i]
36-
} else {
37-
throw new SizeLimitError('unknownEntry', i)
33+
for (let entry of check.entry) {
34+
let matches = Object.keys(outputs).filter(key => parse(key).name === entry)
35+
if(matches.length === 0) {
36+
throw new SizeLimitError('unknownEntry', entry)
37+
}
38+
for(let match of matches) {
39+
entries[match] = outputs[match]
3840
}
3941
}
4042
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import './file.js'
2+
import './style.css'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
a {
2+
color: black
3+
}

packages/esbuild/test/index.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ it('uses esbuild to make bundle', async () => {
6464
expect(existsSync(config.checks[0].esbuildOutfile)).toBe(false)
6565
})
6666

67+
it('supports bundles with css', async () => {
68+
let config = {
69+
checks: [{ files: fixture('esm/nonjs.js') }]
70+
}
71+
await run(config)
72+
expect(config.checks[0].size).toBe(49)
73+
})
74+
6775
it('supports ignore', async () => {
6876
let config = {
6977
checks: [{ files: fixture('cjs/big.js'), ignore: ['redux'] }]

packages/size-limit/size-limit-error.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const MESSAGES = {
3737
unknownArg: arg =>
3838
`Unknown argument *${arg}*. Check command for typo and read docs.`,
3939
unknownEntry: entry =>
40-
`Size Limit didn’t find *${entry}* entry in custom Webpack config`,
40+
`Size Limit didn’t find *${entry}* entry in the custom bundler config`,
4141
unknownOption: opt =>
4242
`Unknown option *${opt}* in config. Check Size Limit docs and version.`
4343
}

packages/size-limit/test/__snapshots__/size-limit-error.test.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ exports[`has error for CLI error without output 1`] = `
1212
`;
1313

1414
exports[`has error for unknown entry 1`] = `
15-
"[41m[30m ERROR [39m[49m [31mSize Limit didn’t find [33madmin[31m entry in custom Webpack config[39m
15+
"[41m[30m ERROR [39m[49m [31mSize Limit didn’t find [33madmin[31m entry in the custom bundler config[39m
1616
"
1717
`;
1818

0 commit comments

Comments
 (0)