Skip to content

Commit 17d325a

Browse files
authored
fix(element-plus): fix build when ssr (unplugin#164)
1 parent 70ccf18 commit 17d325a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/core/resolvers/element-plus.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ export interface ElementPlusResolverOptions {
1010
*/
1111
importStyle?: boolean | 'css' | 'sass'
1212

13+
/**
14+
* use commonjs lib & source css or scss for ssr
15+
*/
16+
ssr?: boolean
17+
1318
/**
1419
* specify element-plus version to load style
1520
*
@@ -48,13 +53,15 @@ function getSideEffectsLegacy(
4853
}
4954

5055
function getSideEffects(dirName: string, options: ElementPlusResolverOptions): SideEffectsInfo | undefined {
51-
const { importStyle = 'css' } = options
56+
const { importStyle = 'css', ssr } = options
57+
const themeFolder = 'element-plus/theme-chalk'
58+
const esComponentsFolder = 'element-plus/es/components'
5259

5360
if (importStyle === 'sass')
54-
return `element-plus/es/components/${dirName}/style`
61+
return ssr ? `${themeFolder}/src/${dirName}.scss` : `${esComponentsFolder}/${dirName}/style`
5562

5663
else if (importStyle === true || importStyle === 'css')
57-
return `element-plus/es/components/${dirName}/style/css`
64+
return ssr ? `${themeFolder}/el-${dirName}.css` : `${esComponentsFolder}/${dirName}/style/css`
5865
}
5966

6067
/**
@@ -73,6 +80,7 @@ export function ElementPlusResolver(
7380
return (name: string) => {
7481
if (name.match(/^El[A-Z]/)) {
7582
const {
83+
ssr,
7684
version = getPkgVersion('element-plus', '1.0.2'),
7785
} = options
7886
const partialName = kebabCase(name.slice(2))// ElTableColumn->table-column
@@ -81,7 +89,7 @@ export function ElementPlusResolver(
8189
if (compareVersions.compare(version, '1.1.0-beta.1', '>=')) {
8290
return {
8391
importName: name,
84-
path: 'element-plus/es',
92+
path: `element-plus/${ssr ? 'lib' : 'es'}`,
8593
sideEffects: getSideEffects(partialName, options),
8694
}
8795
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy