Skip to content

Commit

Permalink
wip: uni_modules 编译模式
Browse files Browse the repository at this point in the history
  • Loading branch information
fxy060608 committed Apr 30, 2024
1 parent 2d1a0e4 commit 8807972
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion packages/uni-h5-vite/src/plugins/easycom.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from 'fs-extra'
import path from 'path'
import type { Plugin } from 'vite'
import { type FilterPattern, createFilter } from '@rollup/pluginutils'
Expand All @@ -15,6 +16,7 @@ import {
genResolveEasycomCode,
isCombineBuiltInCss,
matchEasycom,
normalizePath,
parseVueRequest,
} from '@dcloudio/uni-cli-shared'

Expand Down Expand Up @@ -111,14 +113,33 @@ export function uniEasycomPlugin(options: UniEasycomPluginOptions): Plugin {
}
const source = matchEasycom(name)
if (source) {
const isHelpers = source.includes('uni_helpers')
if (isHelpers) {
const cssFilename = path.join(
process.env.UNI_COMPILE_CLOUD_DIR!,
path.relative(
process.env.UNI_INPUT_DIR,
source.replace(
'?uni_helpers',
'/components/' + name + '/' + name + '.css'
)
)
)
if (fs.existsSync(cssFilename)) {
importDeclarations.push(
`import "${normalizePath(cssFilename)}";`
)
}
}
// 处理easycom组件优先级
return genResolveEasycomCode(
importDeclarations,
str,
addImportDeclaration(
importDeclarations,
`__easycom_${i++}`,
source
source,
isHelpers ? capitalize(camelize(name)) : ''
)
)
}
Expand Down

0 comments on commit 8807972

Please sign in to comment.