Skip to content

fix(element-plus): fix build when ssr #164

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

Merged
merged 2 commits into from
Oct 13, 2021
Merged
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
16 changes: 12 additions & 4 deletions src/core/resolvers/element-plus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export interface ElementPlusResolverOptions {
*/
importStyle?: boolean | 'css' | 'sass'

/**
* use commonjs lib & source css or scss for ssr
*/
ssr?: boolean

/**
* specify element-plus version to load style
*
Expand Down Expand Up @@ -48,13 +53,15 @@ function getSideEffectsLegacy(
}

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

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

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

/**
Expand All @@ -73,6 +80,7 @@ export function ElementPlusResolver(
return (name: string) => {
if (name.match(/^El[A-Z]/)) {
const {
ssr,
version = getPkgVersion('element-plus', '1.0.2'),
} = options
const partialName = kebabCase(name.slice(2))// ElTableColumn->table-column
Expand All @@ -81,7 +89,7 @@ export function ElementPlusResolver(
if (compareVersions.compare(version, '1.1.0-beta.1', '>=')) {
return {
importName: name,
path: 'element-plus/es',
path: `element-plus/${ssr ? 'lib' : 'es'}`,
sideEffects: getSideEffects(partialName, options),
}
}
Expand Down