From d76577c05c04f7154bdfcfdb3137b6e45d4c3f01 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Tue, 29 Aug 2023 15:33:03 +0800 Subject: [PATCH 1/2] feat(element-plus): support nightly option --- src/core/resolvers/element-plus.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/core/resolvers/element-plus.ts b/src/core/resolvers/element-plus.ts index d8425d63..430d4a35 100644 --- a/src/core/resolvers/element-plus.ts +++ b/src/core/resolvers/element-plus.ts @@ -38,6 +38,11 @@ export interface ElementPlusResolverOptions { * a list of component names that have no styles, so resolving their styles file should be prevented */ noStylesComponents?: string[] + + /** + * nightly version + */ + nightly?: boolean } type ElementPlusResolverOptionsResolved = Required> & @@ -73,9 +78,9 @@ function getSideEffectsLegacy( } function getSideEffects(dirName: string, options: ElementPlusResolverOptionsResolved): SideEffectsInfo | undefined { - const { importStyle, ssr } = options - const themeFolder = 'element-plus/theme-chalk' - const esComponentsFolder = 'element-plus/es/components' + const { importStyle, ssr, nightly } = options + const themeFolder = nightly ? '@element-plus/nightly/theme-chalk' : 'element-plus/theme-chalk' + const esComponentsFolder = nightly ? '@element-plus/nightly/es/components' : 'element-plus/es/components' if (importStyle === 'sass') { return ssr @@ -104,13 +109,13 @@ function resolveComponent(name: string, options: ElementPlusResolverOptionsResol } const partialName = kebabCase(name.slice(2))// ElTableColumn -> table-column - const { version, ssr } = options + const { version, ssr, nightly } = options // >=1.1.0-beta.1 - if (compare(version, '1.1.0-beta.1', '>=')) { + if (compare(version, '1.1.0-beta.1', '>=') || nightly) { return { name, - from: `element-plus/${ssr ? 'lib' : 'es'}`, + from: `${ nightly ? '@element-plus/nightly' : 'element-plus'}/${ssr ? 'lib' : 'es'}`, sideEffects: getSideEffects(partialName, options), } } @@ -144,13 +149,13 @@ function resolveDirective(name: string, options: ElementPlusResolverOptionsResol if (!directive) return - const { version, ssr } = options + const { version, ssr, nightly } = options // >=1.1.0-beta.1 - if (compare(version, '1.1.0-beta.1', '>=')) { + if (compare(version, '1.1.0-beta.1', '>=') || nightly) { return { name: directive.importName, - from: `element-plus/${ssr ? 'lib' : 'es'}`, + from: `${ nightly ? '@element-plus/nightly' : 'element-plus' }/${ssr ? 'lib' : 'es'}`, sideEffects: getSideEffects(directive.styleName, options), } } @@ -183,6 +188,7 @@ export function ElementPlusResolver( directives: true, exclude: undefined, noStylesComponents: options.noStylesComponents || [], + nightly: false, ...options, } return optionsResolved From 534c325294f5c9cd0c559479b09a59079f6e50ad Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Tue, 29 Aug 2023 17:38:43 +0800 Subject: [PATCH 2/2] chore: fix lint --- src/core/resolvers/element-plus.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/resolvers/element-plus.ts b/src/core/resolvers/element-plus.ts index 430d4a35..5adfb503 100644 --- a/src/core/resolvers/element-plus.ts +++ b/src/core/resolvers/element-plus.ts @@ -115,7 +115,7 @@ function resolveComponent(name: string, options: ElementPlusResolverOptionsResol if (compare(version, '1.1.0-beta.1', '>=') || nightly) { return { name, - from: `${ nightly ? '@element-plus/nightly' : 'element-plus'}/${ssr ? 'lib' : 'es'}`, + from: `${nightly ? '@element-plus/nightly' : 'element-plus'}/${ssr ? 'lib' : 'es'}`, sideEffects: getSideEffects(partialName, options), } } @@ -155,7 +155,7 @@ function resolveDirective(name: string, options: ElementPlusResolverOptionsResol if (compare(version, '1.1.0-beta.1', '>=') || nightly) { return { name: directive.importName, - from: `${ nightly ? '@element-plus/nightly' : 'element-plus' }/${ssr ? 'lib' : 'es'}`, + from: `${nightly ? '@element-plus/nightly' : 'element-plus'}/${ssr ? 'lib' : 'es'}`, sideEffects: getSideEffects(directive.styleName, options), } }