--bundle --external:/* breaks relative CSS @import
I'm using esbuild to bundle many CSS files into one file.
It has relative imports like this: (These should be bundled)
@import "b.css";But it also has absolute paths for images and fonts like this: (These should not be inlined, and kept as-is)
b {
background: url("/images/epic.png");
}I'm using --external:/* to make all paths that start with / treated as external. But it seems to make all paths external, specifically the @import "b.css" from above, which prevents bundling the files together.
Repro:
Given this setup with 2 files:
$ cat a.css
@import "b.css";
$ cat b.css
b { b: b; }Example 1: esbuild --bundle a.css is correct:
/* b.css */
b {
b: b;
}
/* a.css */Example 2: --bundle --external:z* a.css is also correct. No paths start with z here so we inline the import.
/* b.css */
b {
b: b;
}
/* a.css */Example 3: --bundle --external:b* a.css is also correct. The import path starts with b, so it's treated as external and does not get inlined.
@import "b.css";
/* a.css */Example 4: --bundle --external:/* a.css is not correct. There are no paths that start with / here, so it should be inlined.
@import "b.css";
/* a.css */This seems like a bug where all paths are internally expanded and contain / at the start of their representation and match this filter.
Also when I tested this on Windows, the behavior was a bit different and seemed to depend on the current working directory from where esbuild was ran.
Given this setup:
C:\Users\User\test> tree
C:.
├───bin
│ esbuild.exe
└───css
a.css
b.css
C:\Users\User\test> bin\esbuild.exe --bundle --external:/* css\a.css
@import "./css/b.css";
/* css/a.css */
C:\Users\User\test> cd bin
C:\Users\User\test\bin> esbuild.exe --bundle --external:/* ..\css\a.css
/* ../css/b.css */
b{
b: b;
}
/* ../css/a.css */Source: evanw/esbuild