Skip to content

Commit d3b3cc4

Browse files
Mister-Hopemeteorlxy
andauthoredMay 23, 2024··
feat(core): allow non-default-export client config file (#1564)
Co-authored-by: meteorlxy <meteor.lxy@foxmail.com>
1 parent 5615fd3 commit d3b3cc4

File tree

7 files changed

+35
-2
lines changed

7 files changed

+35
-2
lines changed
 

‎e2e/docs/.vuepress/config.ts

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { viteBundler } from '@vuepress/bundler-vite'
33
import { webpackBundler } from '@vuepress/bundler-webpack'
44
import { defineUserConfig } from 'vuepress'
55
import { path } from 'vuepress/utils'
6+
import { fooPlugin } from './plugins/foo/fooPlugin.js'
67
import { e2eTheme } from './theme/node/e2eTheme.js'
78

89
const E2E_BASE = (process.env.E2E_BASE ?? '/') as '/' | `/${string}/`
@@ -80,4 +81,6 @@ export default defineUserConfig({
8081
}
8182
}
8283
},
84+
85+
plugins: [fooPlugin],
8386
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { getDirname, path } from 'vuepress/utils'
2+
3+
const __dirname = getDirname(import.meta.url)
4+
5+
export const fooPlugin = {
6+
name: 'test-plugin',
7+
clientConfigFile: path.resolve(
8+
__dirname,
9+
'./nonDefaultExportClientConfig.js',
10+
),
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// test non-default-export clientConfig
2+
import './test.css'
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#non-default-export {
2+
font-size: 123px;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# non-default-export
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { expect, test } from '@playwright/test'
2+
3+
test('should apply styles correctly if the client config file does not have default export', async ({
4+
page,
5+
}) => {
6+
await page.goto('client-config/non-default-export.html')
7+
await expect(page.locator('#non-default-export')).toHaveCSS(
8+
'font-size',
9+
'123px',
10+
)
11+
})

‎packages/core/src/app/prepare/prepareClientConfigs.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ export const prepareClientConfigs = async (app: App): Promise<void> => {
1111
// generate client config files entry
1212
const content = `\
1313
${clientConfigFiles
14-
.map((filePath, index) => `import clientConfig${index} from '${filePath}'`)
14+
.map(
15+
(filePath, index) => `import * as clientConfig${index} from '${filePath}'`,
16+
)
1517
.join('\n')}
1618
1719
export const clientConfigs = [
1820
${clientConfigFiles.map((_, index) => ` clientConfig${index},`).join('\n')}
19-
]
21+
].map((m) => m.default).filter(Boolean)
2022
`
2123

2224
await app.writeTemp('internal/clientConfigs.js', content)

0 commit comments

Comments
 (0)
Please sign in to comment.