提交 e406957f 编写于 作者: fxy060608's avatar fxy060608

wip(uts): compiler

上级 7353412e
......@@ -22,6 +22,7 @@
"@babel/parser": "^7.16.4",
"@babel/types": "^7.20.7",
"@dcloudio/uni-cli-shared": "3.0.0-alpha-3080220230428002",
"@dcloudio/uni-i18n": "3.0.0-alpha-3080220230428002",
"@dcloudio/uni-nvue-styler": "3.0.0-alpha-3080220230428002",
"@dcloudio/uni-shared": "3.0.0-alpha-3080220230428002",
"@rollup/pluginutils": "^4.2.0",
......
import path from 'path'
import fs from 'fs-extra'
import {
UniViteCopyPluginOptions,
UniVitePlugin,
emptyDir,
initI18nOptions,
normalizeNodeModules,
normalizePath,
parseManifestJsonOnce,
......@@ -10,6 +13,7 @@ import {
resolveUTSCompiler,
utsPlugins,
} from '@dcloudio/uni-cli-shared'
import { compileI18nJsonStr } from '@dcloudio/uni-i18n'
import type { Plugin } from 'vite'
import { parseImports, uvueOutDir } from './utils'
......@@ -41,7 +45,7 @@ const REMOVED_PLUGINS = [
'vite:reporter',
]
export function uniAppUTSPlugin(): Plugin {
export function uniAppUTSPlugin(): UniVitePlugin {
const inputDir = process.env.UNI_INPUT_DIR
const outputDir = process.env.UNI_OUTPUT_DIR
const mainUTS = resolveMainPathOnce(inputDir)
......@@ -58,6 +62,7 @@ export function uniAppUTSPlugin(): Plugin {
return {
name: 'uni:app-uts',
apply: 'build',
uni: createUniOptions(),
config() {
return {
base: '/', // 强制 base
......@@ -173,3 +178,39 @@ export function main(app: IApp) {
}
`
}
function createUniOptions(): UniVitePlugin['uni'] {
return {
copyOptions() {
const platform = process.env.UNI_PLATFORM
const inputDir = process.env.UNI_INPUT_DIR
const outputDir = process.env.UNI_OUTPUT_DIR
const targets: UniViteCopyPluginOptions['targets'] = []
// 自动化测试时,不启用隐私政策
if (!process.env.UNI_AUTOMATOR_WS_ENDPOINT) {
targets.push({
src: 'androidPrivacy.json',
dest: outputDir,
transform(source) {
const options = initI18nOptions(platform, inputDir, false, true)
if (!options) {
return
}
return compileI18nJsonStr(source.toString(), options)
},
})
const debugFilename = '__nvue_debug__'
if (fs.existsSync(path.resolve(inputDir, debugFilename))) {
targets.push({
src: debugFilename,
dest: outputDir,
})
}
}
return {
assets: ['hybrid/html/**/*', 'uni_modules/*/hybrid/html/**/*'],
targets,
}
},
}
}
......@@ -366,6 +366,9 @@ importers:
'@dcloudio/uni-cli-shared':
specifier: 3.0.0-alpha-3080220230428002
version: link:../uni-cli-shared
'@dcloudio/uni-i18n':
specifier: 3.0.0-alpha-3080220230428002
version: link:../uni-i18n
'@dcloudio/uni-nvue-styler':
specifier: 3.0.0-alpha-3080220230428002
version: link:../uni-nvue-styler
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册