Skip to content
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

feat(core): allow non-default-export client config file #1564

Merged
merged 9 commits into from
May 23, 2024
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
3 changes: 3 additions & 0 deletions e2e/docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { viteBundler } from '@vuepress/bundler-vite'
import { webpackBundler } from '@vuepress/bundler-webpack'
import { defineUserConfig } from 'vuepress'
import { path } from 'vuepress/utils'
import { fooPlugin } from './plugins/foo/fooPlugin.js'
import { e2eTheme } from './theme/node/e2eTheme.js'

const E2E_BASE = (process.env.E2E_BASE ?? '/') as '/' | `/${string}/`
Expand Down Expand Up @@ -80,4 +81,6 @@ export default defineUserConfig({
}
}
},

plugins: [fooPlugin],
})
11 changes: 11 additions & 0 deletions e2e/docs/.vuepress/plugins/foo/fooPlugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { getDirname, path } from 'vuepress/utils'

const __dirname = getDirname(import.meta.url)

export const fooPlugin = {
name: 'test-plugin',
clientConfigFile: path.resolve(
__dirname,
'./nonDefaultExportClientConfig.js',
),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// test non-default-export clientConfig
import './test.css'
3 changes: 3 additions & 0 deletions e2e/docs/.vuepress/plugins/foo/test.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#non-default-export {
font-size: 123px;
}
1 change: 1 addition & 0 deletions e2e/docs/client-config/non-default-export.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# non-default-export
11 changes: 11 additions & 0 deletions e2e/tests/client-config/non-default-export.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { expect, test } from '@playwright/test'

test('should apply styles correctly if the client config file does not have default export', async ({
page,
}) => {
await page.goto('client-config/non-default-export.html')
await expect(page.locator('#non-default-export')).toHaveCSS(
'font-size',
'123px',
)
})
6 changes: 4 additions & 2 deletions packages/core/src/app/prepare/prepareClientConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ export const prepareClientConfigs = async (app: App): Promise<void> => {
// generate client config files entry
const content = `\
${clientConfigFiles
.map((filePath, index) => `import clientConfig${index} from '${filePath}'`)
.map(
(filePath, index) => `import * as clientConfig${index} from '${filePath}'`,
)
.join('\n')}

export const clientConfigs = [
${clientConfigFiles.map((_, index) => ` clientConfig${index},`).join('\n')}
]
].map((m) => m.default).filter(Boolean)
`

await app.writeTemp('internal/clientConfigs.js', content)
Expand Down
Loading