evanw / esbuild

An extremely fast bundler for the web
https://esbuild.github.io/
MIT License
38.17k stars 1.15k forks source link

bundle only css produce empty .js file #3921

Closed bes-internal closed 1 month ago

bes-internal commented 1 month ago

1 - only css

I wish bundle only css and run:

echo " import './some.css'; " | esbuild \
--log-level=info \
--bundle \
--minify \
--platform=browser \
--format=iife \
--outdir=dist/ \

That produce dist/stdin.css as expected and dist/stdin.js with content:

(()=>{})();

Expected: no dist/stdin.js if there is no content of js

2 - only css outfile

I wish bundle only css with use --outfile for that and run:

echo " import './some.css'; " | esbuild \
--log-level=info \
--bundle \
--minify \
--platform=browser \
--format=iife \
--outfile=final.css \

That produce error:

✘ [ERROR] Two output files share the same path but have different contents: css.css

because outfile means one file but there is css content and empty js content!

Expected:

ebsuild produce only final.css if no js bundle output

3 - empty

emtpy input:

echo "  " | esbuild \
--log-level=info \
--bundle \
--minify \
--platform=browser \
--format=iife \

Expected - empty, but produce - (()=>{})();

evanw commented 1 month ago

Instead of echo " import './some.css'; " | esbuild ... you can use either cat some.css | esbuild --loader=css ... or even just esbuild some.css ....

evanw commented 1 month ago

I'm closing this issue as invalid. You are getting a .js file because you are bundling JavaScript. This is expected behavior. You have to bundle only CSS input to produce only CSS output (as described above).