Skip to content

Commit

Permalink
fix: inject style in multi formats (#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmkx committed Dec 10, 2021
1 parent 5e8369c commit 39a8d13
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.ts
Expand Up @@ -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,
})
Expand Down
22 changes: 22 additions & 0 deletions test/index.test.ts
Expand Up @@ -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': `
<span>{msg}</span>
<style>
span {color: red}
</style>`,
},
{
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,
Expand Down

1 comment on commit 39a8d13

@vercel
Copy link

@vercel vercel bot commented on 39a8d13 Dec 10, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.