diff --git a/src/index.ts b/src/index.ts
index 992a3fc1..8462972d 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -195,7 +195,7 @@ export async function build(_options: Options) {
await runEsbuild(options, {
pluginContainer,
format,
- css: index === 0 ? css : undefined,
+ css: (index === 0 || options.injectStyle) ? css : undefined,
logger,
buildDependencies,
})
diff --git a/test/index.test.ts b/test/index.test.ts
index fff059b8..c2fc109c 100644
--- a/test/index.test.ts
+++ b/test/index.test.ts
@@ -692,6 +692,28 @@ test('inject style', async (t) => {
t.assert(output.includes('.hello{color:red}'))
})
+test('inject style in multi formats', async (t) => {
+ const { outFiles, getFileContent } = await run(
+ t.title,
+ {
+ 'input.ts': `export * from './App.svelte'`,
+ 'App.svelte': `
+ {msg}
+
+ `,
+ },
+ {
+ flags: ['--inject-style', '--minify', '--format', 'esm,cjs,iife'],
+ }
+ )
+ t.deepEqual(outFiles, ['input.global.js', 'input.js', 'input.mjs'])
+ for (const file of outFiles) {
+ t.assert((await getFileContent(`dist/${file}`)).includes('{color:red}'))
+ }
+})
+
test('shebang', async (t) => {
const { outDir } = await run(
t.title,