Skip to content

Commit

Permalink
Support css content in esbuild plugin (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
just-boris committed Mar 21, 2024
1 parent 2d063b9 commit ed7b9ab
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 8 deletions.
14 changes: 8 additions & 6 deletions packages/esbuild/index.js
Expand Up @@ -23,18 +23,20 @@ function getFiles(buildResult, check) {
let outputs = buildResult.metafile.outputs

for (let key in outputs) {
let outputEntryName = parse(key).name
let outputEntryName = parse(key).base
outputs[outputEntryName] = outputs[key]
outputs[outputEntryName].path = resolve(key)
delete outputs[key]
}

if (check.entry) {
for (let i of check.entry) {
if (outputs[i]) {
entries[i] = outputs[i]
} else {
throw new SizeLimitError('unknownEntry', i)
for (let entry of check.entry) {
let matches = Object.keys(outputs).filter(key => parse(key).name === entry)
if(matches.length === 0) {
throw new SizeLimitError('unknownEntry', entry)
}
for(let match of matches) {
entries[match] = outputs[match]
}
}
} else {
Expand Down
2 changes: 2 additions & 0 deletions packages/esbuild/test/fixtures/esm/nonjs.js
@@ -0,0 +1,2 @@
import './file.js'
import './style.css'
3 changes: 3 additions & 0 deletions packages/esbuild/test/fixtures/esm/style.css
@@ -0,0 +1,3 @@
a {
color: black
}
8 changes: 8 additions & 0 deletions packages/esbuild/test/index.test.js
Expand Up @@ -64,6 +64,14 @@ it('uses esbuild to make bundle', async () => {
expect(existsSync(config.checks[0].esbuildOutfile)).toBe(false)
})

it('supports bundles with css', async () => {
let config = {
checks: [{ files: fixture('esm/nonjs.js') }]
}
await run(config)
expect(config.checks[0].size).toBe(49)
})

it('supports ignore', async () => {
let config = {
checks: [{ files: fixture('cjs/big.js'), ignore: ['redux'] }]
Expand Down
2 changes: 1 addition & 1 deletion packages/size-limit/size-limit-error.js
Expand Up @@ -37,7 +37,7 @@ const MESSAGES = {
unknownArg: arg =>
`Unknown argument *${arg}*. Check command for typo and read docs.`,
unknownEntry: entry =>
`Size Limit didn’t find *${entry}* entry in custom Webpack config`,
`Size Limit didn’t find *${entry}* entry in the custom bundler config`,
unknownOption: opt =>
`Unknown option *${opt}* in config. Check Size Limit docs and version.`
}
Expand Down
Expand Up @@ -12,7 +12,7 @@ exports[`has error for CLI error without output 1`] = `
`;

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

Expand Down

0 comments on commit ed7b9ab

Please sign in to comment.