Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support css content in esbuild plugin #361

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 8 additions & 6 deletions packages/esbuild/index.js
Original file line number Diff line number Diff line change
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure entry matching still uses path.parse(entry).name as before

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './file.js'
import './style.css'
3 changes: 3 additions & 0 deletions packages/esbuild/test/fixtures/esm/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a {
color: black
}
8 changes: 8 additions & 0 deletions packages/esbuild/test/index.test.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spent some time in confusion how esbuild change may break anything with webpack config. Let's rename the error message to a more generic

unknownOption: opt =>
`Unknown option *${opt}* in config. Check Size Limit docs and version.`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exports[`has error for CLI error without output 1`] = `
`;

exports[`has error for unknown entry 1`] = `
" ERROR  Size Limit didn’t find admin entry in custom Webpack config
" ERROR  Size Limit didn’t find admin entry in the custom bundler config
"
`;

Expand Down