这是indexloc提供的服务,不要输入任何密码
Skip to content

fix: inject style in multi formats #490

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

Merged
merged 1 commit into from
Dec 10, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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