Skip to content

Commit

Permalink
feat(core): allow non-default-export client config file (#1564)
Browse files Browse the repository at this point in the history
Co-authored-by: meteorlxy <meteor.lxy@foxmail.com>
  • Loading branch information
Mister-Hope and meteorlxy committed May 23, 2024
1 parent 5615fd3 commit d3b3cc4
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 2 deletions.
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

0 comments on commit d3b3cc4

Please sign in to comment.