Skip to content

Commit

Permalink
fix(app): Adjust inject-css plugin code for changed plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Apr 21, 2024
1 parent b0f9c79 commit 0ea9cec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion __tests__/appconfig.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('app config', () => {
})

describe('inlining css', () => {
const pluginName = cssInjectedByJsPlugin().name
const pluginName = [cssInjectedByJsPlugin()].flat()[0].name

it('does not inline css by default', async () => {
const resolved = await createConfig()
Expand Down
12 changes: 9 additions & 3 deletions lib/appConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { UserConfig, UserConfigFn } from 'vite'
import type { Plugin, UserConfig, UserConfigFn } from 'vite'
import type { BaseOptions, NodePolyfillsOptions } from './baseConfig.js'

import { relative } from 'node:path'
Expand Down Expand Up @@ -83,10 +83,16 @@ export const createAppConfig = (entries: { [entryAlias: string]: string }, optio
// Make sure we get a user config and not a promise or a user config function
const userConfig = await Promise.resolve(typeof options.config === 'function' ? options.config(env) : options.config)

const plugins = []
const plugins = [] as Plugin[]
// Inject all imported styles into the javascript bundle by creating dynamic styles on the document
if (options.inlineCSS) {
plugins.push(injectCSSPlugin(typeof options.inlineCSS === 'object' ? options.inlineCSS : undefined))
const plugin = injectCSSPlugin({
dev: {
enableDev: env.mode === 'development',
},
...(typeof options.inlineCSS === 'object' ? options.inlineCSS : {}),
})
plugins.push(...[plugin].flat())
}

// defaults to true so only not adding if explicitly set to false
Expand Down

0 comments on commit 0ea9cec

Please sign in to comment.