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

wip(uts): web and mp

上级 0eeb015f
......@@ -2,13 +2,14 @@ declare namespace NodeJS {
interface Process {
UNI_NVUE_ENTRY: Record<string, string>
}
interface ProcessEnv {
NODE_ENV: 'production' | 'development' | 'test'
UNI_NODE_ENV: 'production' | 'development' | 'test'
UNI_PLATFORM: UniApp.PLATFORM
UNI_SUB_PLATFORM: 'quickapp-webview-huawei' | 'quickapp-webview-union'
UNI_APP_PLATFORM: 'android' | 'ios'
UNI_UTS_PLATFORM: 'app-android' | 'app-ios'
UNI_UTS_PLATFORM: 'app-android' | 'app-ios' | 'web' | UniApp.PLATFORM
UNI_INPUT_DIR: string
UNI_OUTPUT_DIR: string
......
......@@ -8,6 +8,7 @@ export const EXTNAME_JS_RE = /\.(js|jsx|ts|tsx|mjs)$/
export const EXTNAME_TS_RE = /\.tsx?$/
export const extensions = [
'.uts',
'.mjs',
'.js',
'.ts',
......
......@@ -14,8 +14,10 @@ import {
updateMiniProgramComponentsByScriptFilename,
updateMiniProgramComponentsByTemplateFilename,
withSourcemap,
resolveUtsModule,
} from '@dcloudio/uni-cli-shared'
import { virtualComponentPath, virtualPagePath } from './entry'
import { CustomPluginOptions, ResolvedId } from 'rollup'
export function uniUsingComponentsPlugin(
options: {
......@@ -49,6 +51,25 @@ export function uniUsingComponentsPlugin(
sourceMap,
dynamicImport,
}
const resolve = async (
source: string,
importer?: string,
options?: {
custom?: CustomPluginOptions
isEntry?: boolean
skipSelf?: boolean
}
): Promise<ResolvedId | null> => {
const id = resolveUtsModule(
source,
importer || process.env.UNI_INPUT_DIR,
process.env.UNI_UTS_PLATFORM
)
if (id) {
source = id
}
return this.resolve(source, importer, options)
}
if (query.vue) {
if (query.type === 'script') {
// 需要主动监听
......@@ -57,7 +78,7 @@ export function uniUsingComponentsPlugin(
filename,
parseAst(source, id),
{
resolve: this.resolve,
resolve,
isExternal: true,
}
)
......@@ -78,7 +99,7 @@ export function uniUsingComponentsPlugin(
filename,
parseAst(source, id),
{
resolve: this.resolve,
resolve,
isExternal: true,
}
)
......@@ -101,7 +122,7 @@ export function uniUsingComponentsPlugin(
const ast = parseAst(source, id)
const descriptor = await parseMainDescriptor(filename, ast, this.resolve)
const descriptor = await parseMainDescriptor(filename, ast, resolve)
updateMiniProgramComponentsByMainFilename(
filename,
......
......@@ -3906,6 +3906,7 @@ function utsStracktraceyPreset(opts) {
return `at ${nixSlashes(path__default["default"].relative(inputRoot, _stack.file.replace('\\\\?\\', '')))}:${_stack.line}:${_stack.column}
${_stack.errMsg}`;
}
return '';
}
return item;
})
......
......@@ -3900,6 +3900,7 @@ function utsStracktraceyPreset(opts) {
return `at ${nixSlashes(path.relative(inputRoot, _stack.file.replace('\\\\?\\', '')))}:${_stack.line}:${_stack.column}
${_stack.errMsg}`;
}
return '';
}
return item;
})
......
......@@ -484,6 +484,7 @@ export function utsStracktraceyPreset(
)}:${_stack.line}:${_stack.column}
${_stack.errMsg}`
}
return ''
}
return item
})
......
import type { Plugin } from 'vite'
import path from 'path'
import {
isInHBuilderX,
parseVueRequest,
resolveUtsModule,
} from '@dcloudio/uni-cli-shared'
import { isInHBuilderX, parseVueRequest } from '@dcloudio/uni-cli-shared'
import {
ClassDeclaration,
ClassExpression,
......@@ -28,13 +24,6 @@ export function uniUtsV1Plugin(): Plugin {
name: 'uni:uts-v1',
apply: 'build',
enforce: 'pre',
resolveId(id, importer) {
return resolveUtsModule(
id,
importer ? path.dirname(importer) : process.env.UNI_INPUT_DIR,
process.env.UNI_UTS_PLATFORM
)
},
async transform(code, id, opts) {
if (opts && opts.ssr) {
return
......
......@@ -190,6 +190,12 @@ function initUtsPlatform(options: CliOptions) {
if (options.platform === 'app' && !process.env.UNI_UTS_PLATFORM) {
process.env.UNI_UTS_PLATFORM = 'app-android'
}
if (options.platform === 'h5') {
process.env.UNI_UTS_PLATFORM = 'web'
}
if (!process.env.UNI_UTS_PLATFORM) {
process.env.UNI_UTS_PLATFORM = options.platform as any
}
}
function initAutomator({ autoHost, autoPort }: CliOptions) {
......
......@@ -43,6 +43,11 @@ export function createConfig(
optimizeDeps: createOptimizeDeps(options),
build: createBuild(options, config),
css: createCss(options, config),
esbuild: {
include: /\.(tsx?|jsx|uts)$/,
exclude: /\.js$/,
loader: 'ts',
},
worker: {
plugins: initFixedEsbuildInitTSConfck(process.env.UNI_INPUT_DIR),
},
......
import path from 'path'
import debug from 'debug'
import { Plugin } from 'vite'
import { resolveBuiltIn } from '@dcloudio/uni-cli-shared'
import { resolveBuiltIn, resolveUtsModule } from '@dcloudio/uni-cli-shared'
import { VitePluginUniResolvedOptions } from '../..'
......@@ -28,7 +28,7 @@ export function uniResolveIdPlugin(
const resolveCache: Record<string, string> = {}
return {
name: 'uni:resolve-id',
resolveId(id) {
resolveId(id, importer) {
const cache = resolveCache[id]
if (cache) {
debugResolve('cache', id, cache)
......@@ -39,6 +39,11 @@ export function uniResolveIdPlugin(
path.join(id, BUILT_IN_MODULES[id as BuiltInModulesKey])
))
}
return resolveUtsModule(
id,
importer ? path.dirname(importer) : process.env.UNI_INPUT_DIR,
process.env.UNI_UTS_PLATFORM
)
},
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册