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

wip(app): transformAssetUrls

上级 dbea30e6
......@@ -12,4 +12,8 @@ export const uniOptions: UniVitePlugin['uni'] = {
transformEvent: {
tap: 'click',
},
transformAssetUrls: {
base: '/',
tags: {},
},
}
import TerserPlugin from 'terser-webpack-plugin'
import { Configuration } from 'webpack'
import { Configuration, WebpackPluginInstance } from 'webpack'
export function createOptimization(): Configuration['optimization'] {
return {
......@@ -13,7 +13,7 @@ export function createOptimization(): Configuration['optimization'] {
ascii_only: true,
},
},
}),
}) as unknown as WebpackPluginInstance,
],
}
}
import { Plugin } from 'vite'
import { ParserOptions } from '@vue/compiler-core'
import { CompilerOptions } from '@vue/compiler-sfc'
import { CompilerOptions, SFCTemplateCompileOptions } from '@vue/compiler-sfc'
export interface UniVitePlugin extends Plugin {
uni?: {
compilerOptions?: {
......@@ -9,6 +9,7 @@ export interface UniVitePlugin extends Plugin {
directiveTransforms?: CompilerOptions['directiveTransforms']
}
transformEvent?: Record<string, string>
transformAssetUrls?: SFCTemplateCompileOptions['transformAssetUrls']
}
}
......
......@@ -24,6 +24,24 @@ const UniH5Plugin = {
transformEvent: {
tap: 'click',
},
transformAssetUrls: {
base: '/',
tags: {
audio: ['src'],
video: ['src', 'poster'],
img: ['src'],
image: ['src'],
'cover-image': ['src'],
// h5
'v-uni-audio': ['src'],
'v-uni-video': ['src', 'poster'],
'v-uni-image': ['src'],
'v-uni-cover-image': ['src'],
// nvue
'u-image': ['src'],
'u-video': ['src', 'poster'],
},
},
},
config(config, env) {
if (uni_cli_shared_1.isInHBuilderX()) {
......
......@@ -21,6 +21,24 @@ const UniH5Plugin: UniVitePlugin = {
transformEvent: {
tap: 'click',
},
transformAssetUrls: {
base: '/',
tags: {
audio: ['src'],
video: ['src', 'poster'],
img: ['src'],
image: ['src'],
'cover-image': ['src'],
// h5
'v-uni-audio': ['src'],
'v-uni-video': ['src', 'poster'],
'v-uni-image': ['src'],
'v-uni-cover-image': ['src'],
// nvue
'u-image': ['src'],
'u-video': ['src', 'poster'],
},
},
},
config(config, env) {
if (isInHBuilderX()) {
......
......@@ -14,29 +14,6 @@ import { transformMatchMedia } from './transforms/transformMatchMedia'
import { createTransformEvent } from './transforms/transformEvent'
// import { transformContext } from './transforms/transformContext'
function createUniVueTransformAssetUrls(
base: string
): SFCTemplateCompileOptions['transformAssetUrls'] {
return {
base,
tags: {
audio: ['src'],
video: ['src', 'poster'],
img: ['src'],
image: ['src'],
'cover-image': ['src'],
// h5
'v-uni-audio': ['src'],
'v-uni-video': ['src', 'poster'],
'v-uni-image': ['src'],
'v-uni-cover-image': ['src'],
// nvue
'u-image': ['src'],
'u-video': ['src', 'poster'],
},
}
}
export function initPluginVueOptions(
options: VitePluginUniResolvedOptions,
UniVitePlugins: UniVitePlugin[]
......@@ -52,18 +29,15 @@ export function initPluginVueOptions(
const templateOptions = vueOptions.template || (vueOptions.template = {})
templateOptions.transformAssetUrls = createUniVueTransformAssetUrls(
options.base
)
let transformAssetUrls: SFCTemplateCompileOptions['transformAssetUrls']
let isCompilerNativeTag: ParserOptions['isNativeTag'] = isNativeTag
let isCompilerCustomElement: ParserOptions['isCustomElement'] =
isCustomElement
let directiveTransforms: CompilerOptions['directiveTransforms']
UniVitePlugins.forEach((plugin) => {
const compilerOptions = plugin.uni?.compilerOptions
UniVitePlugins.forEach(({ uni }) => {
const compilerOptions = uni?.compilerOptions
if (compilerOptions) {
if (compilerOptions.isNativeTag) {
isCompilerNativeTag = compilerOptions.isNativeTag
......@@ -74,14 +48,21 @@ export function initPluginVueOptions(
if (compilerOptions.directiveTransforms) {
directiveTransforms = compilerOptions.directiveTransforms
}
if (uni!.transformAssetUrls) {
transformAssetUrls = uni!.transformAssetUrls
}
}
})
const compilerOptions =
templateOptions.compilerOptions || (templateOptions.compilerOptions = {})
compilerOptions.isNativeTag = isCompilerNativeTag
if (!compilerOptions.nodeTransforms) {
compilerOptions.nodeTransforms = []
}
if (transformAssetUrls) {
templateOptions.transformAssetUrls = transformAssetUrls
}
const compatConfig = parseCompatConfigOnce(options.inputDir)
......
......@@ -9032,6 +9032,11 @@ sort-keys@^4.0.0:
dependencies:
is-plain-obj "^2.0.0"
source-list-map@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-2.0.1.tgz#3993bd873bfc48479cca9ea3a547835c7c154b34"
integrity sha512-qnQ7gVMxGNxsiL4lEuJwe/To8UnK7fAnmbGEEH8RpLouuKbeEm0lhbQVFIrNSuB+G7tVrAlVsZgETT5nljf+Iw==
source-map-js@^0.6.2:
version "0.6.2"
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-0.6.2.tgz#0bb5de631b41cfbda6cfba8bd05a80efdfd2385e"
......@@ -9997,12 +10002,20 @@ webidl-conversions@^6.1.0:
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-6.1.0.tgz#9111b4d7ea80acd40f5270d666621afa78b69514"
integrity sha512-qBIvFLGiBpLjfwmYAaHPXsn+ho5xZnGvyGvsarywGNc8VyQJUMHJ8OBKGGrPER0okBeMDaan4mNBlgBROxuI8w==
webpack-sources@^2.3.0:
version "2.3.1"
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-2.3.1.tgz#570de0af163949fe272233c2cefe1b56f74511fd"
integrity sha512-y9EI9AO42JjEcrTJFOYmVywVZdKVUfOvDUPsJea5GIr1JOEGFVqwlY2K098fFoIjOkDzHn2AjRvM8dsBZu+gCA==
dependencies:
source-list-map "^2.0.1"
source-map "^0.6.1"
webpack-sources@^3.1.2, webpack-sources@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.0.tgz#b16973bcf844ebcdb3afde32eda1c04d0b90f89d"
integrity sha512-fahN08Et7P9trej8xz/Z7eRu8ltyiygEo/hnRi9KqBUs80KeDcnf96ZJo++ewWd84fEf3xSX9bp4ZS9hbw0OBw==
webpack@^5.1.0, webpack@^5.45.1:
webpack@^5.1.0:
version "5.48.0"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.48.0.tgz#06180fef9767a6fd066889559a4c4d49bee19b83"
integrity sha512-CGe+nfbHrYzbk7SKoYITCgN3LRAG0yVddjNUecz9uugo1QtYdiyrVD8nP1PhkNqPfdxC2hknmmKpP355Epyn6A==
......@@ -10032,6 +10045,35 @@ webpack@^5.1.0, webpack@^5.45.1:
watchpack "^2.2.0"
webpack-sources "^3.2.0"
webpack@~5.45.1:
version "5.45.1"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.45.1.tgz#d78dcbeda18a872dc62b0455d3ed3dcfd1c886bb"
integrity sha512-68VT2ZgG9EHs6h6UxfV2SEYewA9BA3SOLSnC2NEbJJiEwbAiueDL033R1xX0jzjmXvMh0oSeKnKgbO2bDXIEyQ==
dependencies:
"@types/eslint-scope" "^3.7.0"
"@types/estree" "^0.0.50"
"@webassemblyjs/ast" "1.11.1"
"@webassemblyjs/wasm-edit" "1.11.1"
"@webassemblyjs/wasm-parser" "1.11.1"
acorn "^8.4.1"
browserslist "^4.14.5"
chrome-trace-event "^1.0.2"
enhanced-resolve "^5.8.0"
es-module-lexer "^0.7.1"
eslint-scope "5.1.1"
events "^3.2.0"
glob-to-regexp "^0.4.1"
graceful-fs "^4.2.4"
json-parse-better-errors "^1.0.2"
loader-runner "^4.2.0"
mime-types "^2.1.27"
neo-async "^2.6.2"
schema-utils "^3.1.0"
tapable "^2.1.1"
terser-webpack-plugin "^5.1.3"
watchpack "^2.2.0"
webpack-sources "^2.3.0"
whatwg-encoding@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/whatwg-encoding/-/whatwg-encoding-1.0.5.tgz#5abacf777c32166a51d085d6b4f3e7d27113ddb0"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册