Skip to content
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

fix: 处理全局样式文件样式不存在时 引入common chunks 中的公共样式文件 #16997

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
12 changes: 11 additions & 1 deletion packages/taro-vite-runner/src/mini/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default function (viteCompilerContext: ViteMiniCompilerContext): PluginOp
name: 'taro:vite-style',
generateBundle (_opts, bundle) {
if (viteCompilerContext) {
const sourceDir = viteCompilerContext.sourceDir
const nativeStyleExt = viteCompilerContext.fileType.style
const appStyleFileName = `app${nativeStyleExt}`
const commonStyleChunks = viteCompilerContext.commonChunks.map(item => `${item}${nativeStyleExt}`)
Expand Down Expand Up @@ -37,7 +38,6 @@ export default function (viteCompilerContext: ViteMiniCompilerContext): PluginOp
// 小程序全局样式文件中引入 common chunks 中的公共样式文件
if (appStyleChunk) {
const APP_STYLE_NAME = 'app-origin' + nativeStyleExt
const sourceDir = viteCompilerContext.sourceDir
this.emitFile({
type: 'asset',
fileName: APP_STYLE_NAME,
Expand All @@ -46,6 +46,16 @@ export default function (viteCompilerContext: ViteMiniCompilerContext): PluginOp
appStyleChunk.source = commonStyleFileNames.reduce((prev, current) => {
return prev + `@import "${path.relative(sourceDir, path.join(sourceDir, current))}";\n`
}, `@import "${APP_STYLE_NAME}";\n`)
} else {
// 处理全局样式文件样式不存在时 引入common chunks 中的公共样式文件
const source = commonStyleFileNames.reduce((prev, current) => {
return prev + `@import "${path.relative(sourceDir, path.join(sourceDir, current))}";\n`;
}, '');
this.emitFile({
type: 'asset',
fileName: appStyleFileName,
source
});
}
}
}
Expand Down