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

feat: transformAssetUrls

上级 3c2123f7
import path from 'path'
import vue from '@vitejs/plugin-vue'
import uni, { uniVueCompilerOptions } from '@dcloudio/vite-plugin-uni'
function resolve(file: string) {
return path.resolve(__dirname, file)
}
import uni, { uniVueTemplateOptions } from '@dcloudio/vite-plugin-uni'
/**
* @type {import('vite').UserConfig}
......@@ -24,9 +20,7 @@ export default {
plugins: [
vue({
template: {
compilerOptions: uniVueCompilerOptions,
},
template: uniVueTemplateOptions,
}),
uni({ inputDir: path.resolve(__dirname, 'src') }),
],
......
export const PUBLIC_DIR = 'static'
export const EXTNAME_JS = ['.js', '.ts']
export const EXTNAME_VUE = ['.vue', '.nvue', '.fvue']
export * from './url'
export * from './json'
export * from './query'
export * from './constants'
export * from './preprocess/index'
......@@ -30,3 +30,12 @@ export function parseVueRequest(id: string) {
query,
}
}
const importQueryRE = /(\?|&)import(?:&|$)/
export const isImportRequest = (url: string) => importQueryRE.test(url)
export const queryRE = /\?.*$/
export const hashRE = /#.*$/
export const cleanUrl = (url: string) =>
url.replace(hashRE, '').replace(queryRE, '')
<template>
<uni-image v-bind="$attrs">
<div
ref="content"
:style="modeStyle"
/>
<img :src="realImagePath">
<div ref="content" :style="modeStyle" />
<img :src="realImagePath" />
<v-uni-resize-sensor
v-if="mode === 'widthFix'"
ref="sensor"
......@@ -13,38 +10,41 @@
</uni-image>
</template>
<script>
import { getRealPath } from '@dcloudio/uni-platform'
export default {
name: 'Image',
props: {
src: {
type: String,
default: ''
default: '',
},
mode: {
type: String,
default: 'scaleToFill'
default: 'scaleToFill',
},
// TODO 懒加载
lazyLoad: {
type: [Boolean, String],
default: false
}
default: false,
},
},
data () {
data() {
return {
originalWidth: 0,
originalHeight: 0,
availHeight: ''
availHeight: '',
}
},
computed: {
ratio () {
return this.originalWidth && this.originalHeight ? this.originalWidth / this.originalHeight : 0
ratio() {
return this.originalWidth && this.originalHeight
? this.originalWidth / this.originalHeight
: 0
},
realImagePath () {
return this.$getRealPath(this.src)
realImagePath() {
return getRealPath(this.src)
},
modeStyle () {
modeStyle() {
let size = 'auto'
let position = ''
const repeat = 'no-repeat'
......@@ -95,23 +95,23 @@ export default {
}
return `background-position:${position};background-size:${size};background-repeat:${repeat};`
}
},
},
watch: {
src (newValue, oldValue) {
src(newValue, oldValue) {
this._setContentImage()
this._loadImage()
},
mode (newValue, oldValue) {
mode(newValue, oldValue) {
if (oldValue === 'widthFix') {
this.$el.style.height = this.availHeight
}
if (newValue === 'widthFix' && this.ratio) {
this._fixSize()
}
}
},
},
mounted () {
mounted() {
this.availHeight = this.$el.style.height || ''
this._setContentImage()
if (!this.realImagePath) {
......@@ -120,26 +120,32 @@ export default {
this._loadImage()
},
methods: {
_resize () {
_resize() {
if (this.mode === 'widthFix') {
this._fixSize()
}
},
_fixSize () {
_fixSize() {
const elWidth = this._getWidth()
if (elWidth) {
let height = elWidth / this.ratio
// fix: 解决 Chrome 浏览器上某些情况下导致 1px 缝隙的问题
if (typeof navigator && navigator.vendor === 'Google Inc.' && height > 10) {
if (
typeof navigator &&
navigator.vendor === 'Google Inc.' &&
height > 10
) {
height = Math.round(height / 2) * 2
}
this.$el.style.height = height + 'px'
}
},
_setContentImage () {
this.$refs.content.style.backgroundImage = this.src ? `url("${this.realImagePath}")` : 'none'
_setContentImage() {
this.$refs.content.style.backgroundImage = this.src
? `url("${this.realImagePath}")`
: 'none'
},
_loadImage () {
_loadImage() {
const _self = this
const img = new Image()
img.onload = function ($event) {
......@@ -152,59 +158,61 @@ export default {
_self.$trigger('load', $event, {
width: this.width,
height: this.height
height: this.height,
})
}
img.onerror = function ($event) {
_self.$trigger('error', $event, {
errMsg: `GET ${_self.src} 404 (Not Found)`
errMsg: `GET ${_self.src} 404 (Not Found)`,
})
}
img.src = this.realImagePath
},
_getWidth () {
_getWidth() {
const computedStyle = window.getComputedStyle(this.$el)
const borderWidth = (parseFloat(computedStyle.borderLeftWidth, 10) || 0) + (parseFloat(computedStyle.borderRightWidth,
10) || 0)
const paddingWidth = (parseFloat(computedStyle.paddingLeft, 10) || 0) + (parseFloat(computedStyle.paddingRight, 10) ||
0)
const borderWidth =
(parseFloat(computedStyle.borderLeftWidth, 10) || 0) +
(parseFloat(computedStyle.borderRightWidth, 10) || 0)
const paddingWidth =
(parseFloat(computedStyle.paddingLeft, 10) || 0) +
(parseFloat(computedStyle.paddingRight, 10) || 0)
return this.$el.offsetWidth - borderWidth - paddingWidth
}
}
},
},
}
</script>
<style>
uni-image {
width: 320px;
height: 240px;
display: inline-block;
overflow: hidden;
position: relative;
}
uni-image {
width: 320px;
height: 240px;
display: inline-block;
overflow: hidden;
position: relative;
}
uni-image[hidden] {
display: none;
}
uni-image[hidden] {
display: none;
}
uni-image>div {
width: 100%;
height: 100%;
}
uni-image > div {
width: 100%;
height: 100%;
}
uni-image>img {
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none;
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
}
uni-image > img {
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none;
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
}
uni-image>.uni-image-will-change {
will-change: transform;
}
uni-image > .uni-image-will-change {
will-change: transform;
}
</style>
......@@ -26,8 +26,3 @@ export function $handleEvent(this: ComponentPublicInstance, $event: Event) {
}
return $event
}
export function $getRealPath(v: string) {
// TODO
return v
}
uni-canvas {
width: 300px;
height: 150px;
display: block;
position: relative;
}
uni-canvas > canvas {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
uni-checkbox-group[hidden] {
display: none;
}
.ql-container {
display: block;
position: relative;
box-sizing: border-box;
-webkit-user-select: text;
user-select: text;
outline: none;
overflow: hidden;
width: 100%;
height: 200px;
min-height: 200px;
}
.ql-container[hidden] {
display: none;
}
.ql-container .ql-editor {
position: relative;
font-size: inherit;
line-height: inherit;
font-family: inherit;
min-height: inherit;
width: 100%;
height: 100%;
padding: 0;
overflow-x: hidden;
overflow-y: auto;
-webkit-tap-highlight-color: transparent;
-webkit-touch-callout: none;
-webkit-overflow-scrolling: touch;
}
.ql-container .ql-editor::-webkit-scrollbar {
width: 0 !important;
}
.ql-container .ql-editor.scroll-disabled {
overflow: hidden;
}
.ql-container .ql-image-overlay {
display: flex;
position: absolute;
box-sizing: border-box;
border: 1px dashed #ccc;
justify-content: center;
align-items: center;
-webkit-user-select: none;
user-select: none;
}
.ql-container .ql-image-overlay .ql-image-size {
position: absolute;
padding: 4px 8px;
text-align: center;
background-color: #fff;
color: #888;
border: 1px solid #ccc;
box-sizing: border-box;
opacity: 0.8;
right: 4px;
top: 4px;
font-size: 12px;
display: inline-block;
width: auto;
}
.ql-container .ql-image-overlay .ql-image-toolbar {
position: relative;
text-align: center;
box-sizing: border-box;
background: #000;
border-radius: 5px;
color: #fff;
font-size: 0;
min-height: 24px;
z-index: 100;
}
.ql-container .ql-image-overlay .ql-image-toolbar span {
display: inline-block;
cursor: pointer;
padding: 5px;
font-size: 12px;
border-right: 1px solid #fff;
}
.ql-container .ql-image-overlay .ql-image-toolbar span:last-child {
border-right: 0;
}
.ql-container .ql-image-overlay .ql-image-toolbar span.triangle-up {
padding: 0;
position: absolute;
top: -12px;
left: 50%;
transform: translatex(-50%);
width: 0;
height: 0;
border-width: 6px;
border-style: solid;
border-color: transparent transparent black transparent;
}
.ql-container .ql-image-overlay .ql-image-handle {
position: absolute;
height: 12px;
width: 12px;
border-radius: 50%;
border: 1px solid #ccc;
box-sizing: border-box;
background: #fff;
}
.ql-container img {
display: inline-block;
max-width: 100%;
}
.ql-clipboard p {
margin: 0;
padding: 0;
}
.ql-editor {
box-sizing: border-box;
height: 100%;
outline: none;
overflow-y: auto;
tab-size: 4;
-moz-tab-size: 4;
text-align: left;
white-space: pre-wrap;
word-wrap: break-word;
}
.ql-editor > * {
cursor: text;
}
.ql-editor p,
.ql-editor ol,
.ql-editor ul,
.ql-editor pre,
.ql-editor blockquote,
.ql-editor h1,
.ql-editor h2,
.ql-editor h3,
.ql-editor h4,
.ql-editor h5,
.ql-editor h6 {
margin: 0;
padding: 0;
counter-reset: list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9;
}
.ql-editor ol > li,
.ql-editor ul > li {
list-style-type: none;
}
.ql-editor ul > li::before {
content: '\2022';
}
.ql-editor ul[data-checked=true],
.ql-editor ul[data-checked=false] {
pointer-events: none;
}
.ql-editor ul[data-checked=true] > li *,
.ql-editor ul[data-checked=false] > li * {
pointer-events: all;
}
.ql-editor ul[data-checked=true] > li::before,
.ql-editor ul[data-checked=false] > li::before {
color: #777;
cursor: pointer;
pointer-events: all;
}
.ql-editor ul[data-checked=true] > li::before {
content: '\2611';
}
.ql-editor ul[data-checked=false] > li::before {
content: '\2610';
}
.ql-editor li::before {
display: inline-block;
white-space: nowrap;
width: 2em;
}
.ql-editor ol li {
counter-reset: list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9;
counter-increment: list-0;
}
.ql-editor ol li:before {
content: counter(list-0, decimal) '. ';
}
.ql-editor ol li.ql-indent-1 {
counter-increment: list-1;
}
.ql-editor ol li.ql-indent-1:before {
content: counter(list-1, lower-alpha) '. ';
}
.ql-editor ol li.ql-indent-1 {
counter-reset: list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9;
}
.ql-editor ol li.ql-indent-2 {
counter-increment: list-2;
}
.ql-editor ol li.ql-indent-2:before {
content: counter(list-2, lower-roman) '. ';
}
.ql-editor ol li.ql-indent-2 {
counter-reset: list-3 list-4 list-5 list-6 list-7 list-8 list-9;
}
.ql-editor ol li.ql-indent-3 {
counter-increment: list-3;
}
.ql-editor ol li.ql-indent-3:before {
content: counter(list-3, decimal) '. ';
}
.ql-editor ol li.ql-indent-3 {
counter-reset: list-4 list-5 list-6 list-7 list-8 list-9;
}
.ql-editor ol li.ql-indent-4 {
counter-increment: list-4;
}
.ql-editor ol li.ql-indent-4:before {
content: counter(list-4, lower-alpha) '. ';
}
.ql-editor ol li.ql-indent-4 {
counter-reset: list-5 list-6 list-7 list-8 list-9;
}
.ql-editor ol li.ql-indent-5 {
counter-increment: list-5;
}
.ql-editor ol li.ql-indent-5:before {
content: counter(list-5, lower-roman) '. ';
}
.ql-editor ol li.ql-indent-5 {
counter-reset: list-6 list-7 list-8 list-9;
}
.ql-editor ol li.ql-indent-6 {
counter-increment: list-6;
}
.ql-editor ol li.ql-indent-6:before {
content: counter(list-6, decimal) '. ';
}
.ql-editor ol li.ql-indent-6 {
counter-reset: list-7 list-8 list-9;
}
.ql-editor ol li.ql-indent-7 {
counter-increment: list-7;
}
.ql-editor ol li.ql-indent-7:before {
content: counter(list-7, lower-alpha) '. ';
}
.ql-editor ol li.ql-indent-7 {
counter-reset: list-8 list-9;
}
.ql-editor ol li.ql-indent-8 {
counter-increment: list-8;
}
.ql-editor ol li.ql-indent-8:before {
content: counter(list-8, lower-roman) '. ';
}
.ql-editor ol li.ql-indent-8 {
counter-reset: list-9;
}
.ql-editor ol li.ql-indent-9 {
counter-increment: list-9;
}
.ql-editor ol li.ql-indent-9:before {
content: counter(list-9, decimal) '. ';
}
.ql-editor .ql-indent-1:not(.ql-direction-rtl) {
padding-left: 2em;
}
.ql-editor li.ql-indent-1:not(.ql-direction-rtl) {
padding-left: 2em;
}
.ql-editor .ql-indent-1.ql-direction-rtl.ql-align-right {
padding-right: 2em;
}
.ql-editor li.ql-indent-1.ql-direction-rtl.ql-align-right {
padding-right: 2em;
}
.ql-editor .ql-indent-2:not(.ql-direction-rtl) {
padding-left: 4em;
}
.ql-editor li.ql-indent-2:not(.ql-direction-rtl) {
padding-left: 4em;
}
.ql-editor .ql-indent-2.ql-direction-rtl.ql-align-right {
padding-right: 4em;
}
.ql-editor li.ql-indent-2.ql-direction-rtl.ql-align-right {
padding-right: 4em;
}
.ql-editor .ql-indent-3:not(.ql-direction-rtl) {
padding-left: 6em;
}
.ql-editor li.ql-indent-3:not(.ql-direction-rtl) {
padding-left: 6em;
}
.ql-editor .ql-indent-3.ql-direction-rtl.ql-align-right {
padding-right: 6em;
}
.ql-editor li.ql-indent-3.ql-direction-rtl.ql-align-right {
padding-right: 6em;
}
.ql-editor .ql-indent-4:not(.ql-direction-rtl) {
padding-left: 8em;
}
.ql-editor li.ql-indent-4:not(.ql-direction-rtl) {
padding-left: 8em;
}
.ql-editor .ql-indent-4.ql-direction-rtl.ql-align-right {
padding-right: 8em;
}
.ql-editor li.ql-indent-4.ql-direction-rtl.ql-align-right {
padding-right: 8em;
}
.ql-editor .ql-indent-5:not(.ql-direction-rtl) {
padding-left: 10em;
}
.ql-editor li.ql-indent-5:not(.ql-direction-rtl) {
padding-left: 10em;
}
.ql-editor .ql-indent-5.ql-direction-rtl.ql-align-right {
padding-right: 10em;
}
.ql-editor li.ql-indent-5.ql-direction-rtl.ql-align-right {
padding-right: 10em;
}
.ql-editor .ql-indent-6:not(.ql-direction-rtl) {
padding-left: 12em;
}
.ql-editor li.ql-indent-6:not(.ql-direction-rtl) {
padding-left: 12em;
}
.ql-editor .ql-indent-6.ql-direction-rtl.ql-align-right {
padding-right: 12em;
}
.ql-editor li.ql-indent-6.ql-direction-rtl.ql-align-right {
padding-right: 12em;
}
.ql-editor .ql-indent-7:not(.ql-direction-rtl) {
padding-left: 14em;
}
.ql-editor li.ql-indent-7:not(.ql-direction-rtl) {
padding-left: 14em;
}
.ql-editor .ql-indent-7.ql-direction-rtl.ql-align-right {
padding-right: 14em;
}
.ql-editor li.ql-indent-7.ql-direction-rtl.ql-align-right {
padding-right: 14em;
}
.ql-editor .ql-indent-8:not(.ql-direction-rtl) {
padding-left: 16em;
}
.ql-editor li.ql-indent-8:not(.ql-direction-rtl) {
padding-left: 16em;
}
.ql-editor .ql-indent-8.ql-direction-rtl.ql-align-right {
padding-right: 16em;
}
.ql-editor li.ql-indent-8.ql-direction-rtl.ql-align-right {
padding-right: 16em;
}
.ql-editor .ql-indent-9:not(.ql-direction-rtl) {
padding-left: 18em;
}
.ql-editor li.ql-indent-9:not(.ql-direction-rtl) {
padding-left: 18em;
}
.ql-editor .ql-indent-9.ql-direction-rtl.ql-align-right {
padding-right: 18em;
}
.ql-editor li.ql-indent-9.ql-direction-rtl.ql-align-right {
padding-right: 18em;
}
.ql-editor .ql-direction-rtl {
direction: rtl;
text-align: inherit;
}
.ql-editor .ql-align-center {
text-align: center;
}
.ql-editor .ql-align-justify {
text-align: justify;
}
.ql-editor .ql-align-right {
text-align: right;
}
.ql-editor.ql-blank::before {
color: rgba(0, 0, 0, 0.6);
content: attr(data-placeholder);
font-style: italic;
pointer-events: none;
position: absolute;
}
.ql-container.ql-disabled .ql-editor ul[data-checked] > li::before {
pointer-events: none;
}
.ql-clipboard {
left: -100000px;
height: 1px;
overflow-y: hidden;
position: absolute;
top: 50%;
}
uni-image {
width: 320px;
height: 240px;
display: inline-block;
overflow: hidden;
position: relative;
}
uni-image[hidden] {
display: none;
}
uni-image > div {
width: 100%;
height: 100%;
}
uni-image > img {
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none;
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
}
uni-image > .uni-image-will-change {
will-change: transform;
}
.uni-label-pointer {
cursor: pointer;
}
uni-movable-view {
display: inline-block;
width: 10px;
height: 10px;
top: 0px;
left: 0px;
position: absolute;
cursor: grab;
}
uni-movable-view[hidden] {
display: none;
}
uni-navigator {
height: auto;
width: auto;
display: block;
cursor: pointer;
}
uni-navigator[hidden] {
display: none;
}
.navigator-hover {
background-color: rgba(0, 0, 0, 0.1);
opacity: 0.7;
}
uni-radio {
-webkit-tap-highlight-color: transparent;
display: inline-block;
cursor: pointer;
}
uni-radio[hidden] {
display: none;
}
uni-radio[disabled] {
cursor: not-allowed;
}
uni-radio .uni-radio-wrapper {
display: -webkit-inline-flex;
display: inline-flex;
-webkit-align-items: center;
align-items: center;
vertical-align: middle;
}
uni-radio .uni-radio-input {
-webkit-appearance: none;
appearance: none;
margin-right: 5px;
outline: 0;
border: 1px solid #D1D1D1;
background-color: #ffffff;
border-radius: 50%;
width: 22px;
height: 22px;
position: relative;
}
uni-radio:not([disabled]) .uni-radio-input:hover {
border-color: #007aff;
}
uni-radio .uni-radio-input.uni-radio-input-checked:before {
font: normal normal normal 14px/1 "uni";
content: "\EA08";
color: #ffffff;
font-size: 18px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -48%) scale(0.73);
-webkit-transform: translate(-50%, -48%) scale(0.73);
}
uni-radio .uni-radio-input.uni-radio-input-disabled {
background-color: #E1E1E1;
border-color: #D1D1D1;
}
uni-radio .uni-radio-input.uni-radio-input-disabled:before {
color: #ADADAD;
}
uni-radio-group {
display: block;
}
uni-radio-group[hidden] {
display: none;
}
@keyframes once-show {
from {
top: 0;
}
}
uni-resize-sensor,
uni-resize-sensor > div {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
overflow: hidden;
}
uni-resize-sensor {
display: block;
z-index: -1;
visibility: hidden;
animation: once-show 1ms;
}
uni-resize-sensor > div > div {
position: absolute;
left: 0;
top: 0;
}
uni-resize-sensor > div:first-child > div {
width: 100000px;
height: 100000px;
}
uni-resize-sensor > div:last-child > div {
width: 200%;
height: 200%;
}
uni-scroll-view {
display: block;
width: 100%;
}
uni-scroll-view[hidden] {
display: none;
}
.uni-scroll-view {
position: relative;
-webkit-overflow-scrolling: touch;
width: 100%;
/* display: flex; 时在安卓下会导致scrollWidth和offsetWidth一样 */
height: 100%;
max-height: inherit;
}
.uni-scroll-view-content {
width: 100%;
height: 100%;
}
.uni-scroll-view-refresher {
position: relative;
overflow: hidden;
}
.uni-scroll-view-refresh {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.uni-scroll-view-refresh-inner {
display: flex;
align-items: center;
justify-content: center;
line-height: 0;
width: 40px;
height: 40px;
border-radius: 50%;
background-color: #fff;
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.117647),
0 1px 4px rgba(0, 0, 0, 0.117647);
}
.uni-scroll-view-refresh__spinner {
transform-origin: center center;
animation: uni-scroll-view-refresh-rotate 2s linear infinite;
}
.uni-scroll-view-refresh__spinner > circle {
stroke: currentColor;
stroke-linecap: round;
animation: uni-scroll-view-refresh-dash 2s linear infinite;
}
@keyframes uni-scroll-view-refresh-rotate {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
@keyframes uni-scroll-view-refresh-dash {
0% {
stroke-dasharray: 1, 200;
stroke-dashoffset: 0;
}
50% {
stroke-dasharray: 89, 200;
stroke-dashoffset: -35px;
}
100% {
stroke-dasharray: 89, 200;
stroke-dashoffset: -124px;
}
}
uni-swiper-item {
display: block;
overflow: hidden;
will-change: transform;
position: absolute;
width: 100%;
height: 100%;
cursor: grab;
}
uni-swiper-item[hidden] {
display: none;
}
uni-switch {
-webkit-tap-highlight-color: transparent;
display: inline-block;
cursor: pointer;
}
uni-switch[hidden] {
display: none;
}
uni-switch[disabled] {
cursor: not-allowed;
}
uni-switch .uni-switch-wrapper {
display: -webkit-inline-flex;
display: inline-flex;
-webkit-align-items: center;
align-items: center;
vertical-align: middle;
}
uni-switch .uni-switch-input {
-webkit-appearance: none;
appearance: none;
position: relative;
width: 52px;
height: 32px;
margin-right: 5px;
border: 1px solid #DFDFDF;
outline: 0;
border-radius: 16px;
box-sizing: border-box;
background-color: #DFDFDF;
transition: background-color 0.1s, border 0.1s;
}
uni-switch[disabled] .uni-switch-input {
opacity: .7;
}
uni-switch .uni-switch-input:before {
content: " ";
position: absolute;
top: 0;
left: 0;
width: 50px;
height: 30px;
border-radius: 15px;
background-color: #FDFDFD;
transition: -webkit-transform 0.3s;
transition: transform 0.3s;
transition: transform 0.3s, -webkit-transform 0.3s;
}
uni-switch .uni-switch-input:after {
content: " ";
position: absolute;
top: 0;
left: 0;
width: 30px;
height: 30px;
border-radius: 15px;
background-color: #FFFFFF;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
transition: -webkit-transform 0.3s;
transition: transform 0.3s;
transition: transform 0.3s, -webkit-transform 0.3s;
}
uni-switch .uni-switch-input.uni-switch-input-checked {
border-color: #007aff;
background-color: #007aff;
}
uni-switch .uni-switch-input.uni-switch-input-checked:before {
-webkit-transform: scale(0);
transform: scale(0);
}
uni-switch .uni-switch-input.uni-switch-input-checked:after {
-webkit-transform: translateX(20px);
transform: translateX(20px);
}
uni-switch .uni-checkbox-input {
margin-right: 5px;
-webkit-appearance: none;
appearance: none;
outline: 0;
border: 1px solid #D1D1D1;
background-color: #FFFFFF;
border-radius: 3px;
width: 22px;
height: 22px;
position: relative;
color: #007aff;
}
uni-switch:not([disabled]) .uni-checkbox-input:hover {
border-color: #007aff;
}
uni-switch .uni-checkbox-input.uni-checkbox-input-checked:before {
font: normal normal normal 14px/1 "uni";
content: "\EA08";
color: inherit;
font-size: 22px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -48%) scale(0.73);
-webkit-transform: translate(-50%, -48%) scale(0.73);
}
uni-switch .uni-checkbox-input.uni-checkbox-input-disabled {
background-color: #E1E1E1;
}
uni-switch .uni-checkbox-input.uni-checkbox-input-disabled:before {
color: #ADADAD;
}
uni-text[selectable] {
cursor: auto;
user-select: text;
-webkit-user-select: text;
}
uni-textarea {
width: 300px;
height: 150px;
display: block;
position: relative;
font-size: 16px;
line-height: normal;
white-space: pre-wrap;
word-break: break-all;
}
uni-textarea[hidden] {
display: none;
}
.uni-textarea-wrapper,
.uni-textarea-placeholder,
.uni-textarea-line,
.uni-textarea-compute,
.uni-textarea-textarea {
outline: none;
border: none;
padding: 0;
margin: 0;
text-decoration: inherit;
}
.uni-textarea-wrapper {
display: block;
position: relative;
width: 100%;
height: 100%;
}
.uni-textarea-placeholder,
.uni-textarea-line,
.uni-textarea-compute,
.uni-textarea-textarea {
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
white-space: inherit;
word-break: inherit;
}
.uni-textarea-placeholder {
color: grey;
overflow: hidden;
}
.uni-textarea-line,
.uni-textarea-compute {
visibility: hidden;
height: auto;
}
.uni-textarea-line {
width: 1em;
}
.uni-textarea-textarea {
resize: none;
background: none;
color: inherit;
opacity: 1;
-webkit-text-fill-color: currentcolor;
font: inherit;
line-height: inherit;
letter-spacing: inherit;
text-align: inherit;
text-indent: inherit;
text-transform: inherit;
text-shadow: inherit;
}
/* 用于解决 iOS textarea 内部默认边距 */
.uni-textarea-textarea-fix-margin {
width: auto;
right: 0;
margin: 0 -3px;
}
.uni-async-error {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
color: #999;
padding: 100px 10px;
text-align: center;
}
.uni-async-loading {
box-sizing: border-box;
width: 100%;
padding: 50px;
text-align: center;
}
.uni-async-loading .uni-loading {
width: 30px;
height: 30px;
}
......@@ -445,15 +445,11 @@ function $handleEvent($event) {
}
return $event;
}
function $getRealPath(v2) {
return v2;
}
var instance = /* @__PURE__ */ Object.freeze({
__proto__: null,
[Symbol.toStringTag]: "Module",
$trigger,
$handleEvent,
$getRealPath
$handleEvent
});
const CLASS_RE = /^\s+|\s+$/g;
const WXS_CLASS_RE = /\s+/;
......@@ -891,6 +887,12 @@ function createPageState(type) {
function isPage(vm) {
return vm.$options.mpType === "page";
}
function normalizeRoute(path) {
if (path.indexOf("/") === 0) {
return path.substr(1);
}
return path;
}
function initPublicPage(route) {
if (!route) {
const {path} = __uniRoutes[0];
......@@ -899,7 +901,7 @@ function initPublicPage(route) {
return {
id,
path: route.path,
route: route.meta.pagePath,
route: normalizeRoute(route.meta.route || route.path),
fullPath: route.meta.isEntry ? route.meta.pagePath : route.fullPath,
options: {},
meta: usePageMeta()
......@@ -908,7 +910,7 @@ function initPublicPage(route) {
function initPage(vm) {
currentPages.push(vm);
const route = vm.$route;
vm.__page__ = initPublicPage(route);
vm.$page = initPublicPage(route);
}
function routeCache(key, cache, pruneCacheEntry) {
const pageId = parseInt(key.split(SEP)[1]);
......@@ -3303,7 +3305,41 @@ var index$1 = defineComponent({
return () => createVNode("uni-icon", null, [path.value.d && createSvgIconVNode(path.value.d, props.color || path.value.c, rpx2px(props.size))]);
}
});
var index_vue_vue_type_style_index_0_lang$d = "\nuni-image {\r\n width: 320px;\r\n height: 240px;\r\n display: inline-block;\r\n overflow: hidden;\r\n position: relative;\n}\nuni-image[hidden] {\r\n display: none;\n}\nuni-image>div {\r\n width: 100%;\r\n height: 100%;\n}\nuni-image>img {\r\n -webkit-touch-callout: none;\r\n -webkit-user-select: none;\r\n -moz-user-select: none;\r\n display: block;\r\n position: absolute;\r\n top: 0;\r\n left: 0;\r\n width: 100%;\r\n height: 100%;\r\n opacity: 0;\n}\nuni-image>.uni-image-will-change {\r\n will-change: transform;\n}\r\n";
const SCHEME_RE = /^([a-z-]+:)?\/\//i;
const DATA_RE = /^data:.*,.*/;
function addBase(filePath) {
const base = __uniConfig.router.base;
if (!base) {
return filePath;
}
if (base !== "/") {
if (("/" + filePath).indexOf(base) === 0) {
return "/" + filePath;
}
}
return base + filePath;
}
function getRealPath$1(filePath) {
if (__uniConfig.router.base === "./") {
filePath = filePath.replace(/^\.\/static\//, "/static/");
}
if (filePath.indexOf("/") === 0) {
if (filePath.indexOf("//") === 0) {
filePath = "https:" + filePath;
} else {
return addBase(filePath.substr(1));
}
}
if (SCHEME_RE.test(filePath) || DATA_RE.test(filePath) || filePath.indexOf("blob:") === 0) {
return filePath;
}
const pages = getCurrentPages();
if (pages.length) {
return addBase(getRealRoute(pages[pages.length - 1].$page.route, filePath).substr(1));
}
return filePath;
}
var index_vue_vue_type_style_index_0_lang$d = "\nuni-image {\r\n width: 320px;\r\n height: 240px;\r\n display: inline-block;\r\n overflow: hidden;\r\n position: relative;\n}\nuni-image[hidden] {\r\n display: none;\n}\nuni-image > div {\r\n width: 100%;\r\n height: 100%;\n}\nuni-image > img {\r\n -webkit-touch-callout: none;\r\n -webkit-user-select: none;\r\n -moz-user-select: none;\r\n display: block;\r\n position: absolute;\r\n top: 0;\r\n left: 0;\r\n width: 100%;\r\n height: 100%;\r\n opacity: 0;\n}\nuni-image > .uni-image-will-change {\r\n will-change: transform;\n}\r\n";
const _sfc_main$j = {
name: "Image",
props: {
......@@ -3332,7 +3368,7 @@ const _sfc_main$j = {
return this.originalWidth && this.originalHeight ? this.originalWidth / this.originalHeight : 0;
},
realImagePath() {
return this.$getRealPath(this.src);
return getRealPath$1(this.src);
},
modeStyle() {
let size = "auto";
......@@ -8094,7 +8130,7 @@ const reLaunch = /* @__PURE__ */ createAsyncApi("reLaunch", () => {
});
const switchTab = /* @__PURE__ */ createAsyncApi("switchTab", () => {
});
const getRealPath$1 = /* @__PURE__ */ createSyncApi("getRealPath", (path) => {
const getRealPath = /* @__PURE__ */ createSyncApi("getRealPath", (path) => {
return path;
});
var api = /* @__PURE__ */ Object.freeze({
......@@ -8119,7 +8155,7 @@ var api = /* @__PURE__ */ Object.freeze({
redirectTo,
reLaunch,
switchTab,
getRealPath: getRealPath$1
getRealPath
});
const uni$1 = api;
const UniServiceJSBridge$1 = extend(ServiceJSBridge, {
......@@ -8216,40 +8252,6 @@ function usePageHeadTransparent(headRef, {titleColor, coverage, backgroundColor}
});
});
}
const SCHEME_RE = /^([a-z-]+:)?\/\//i;
const DATA_RE = /^data:.*,.*/;
function addBase(filePath) {
const base = __uniConfig.router.base;
if (!base) {
return filePath;
}
if (base !== "/") {
if (("/" + filePath).indexOf(base) === 0) {
return "/" + filePath;
}
}
return base + filePath;
}
function getRealPath(filePath) {
if (__uniConfig.router.base === "./") {
filePath = filePath.replace(/^\.\/static\//, "/static/");
}
if (filePath.indexOf("/") === 0) {
if (filePath.indexOf("//") === 0) {
filePath = "https:" + filePath;
} else {
return addBase(filePath.substr(1));
}
}
if (SCHEME_RE.test(filePath) || DATA_RE.test(filePath) || filePath.indexOf("blob:") === 0) {
return filePath;
}
const pages = getCurrentPages();
if (pages.length) {
return addBase(getRealRoute(pages[pages.length - 1].$page.route, filePath).substr(1));
}
return filePath;
}
const ICON_PATH_BACK = "M21.781 7.844l-9.063 8.594 9.063 8.594q0.25 0.25 0.25 0.609t-0.25 0.578q-0.25 0.25-0.578 0.25t-0.578-0.25l-9.625-9.125q-0.156-0.125-0.203-0.297t-0.047-0.359q0-0.156 0.047-0.328t0.203-0.297l9.625-9.125q0.25-0.25 0.578-0.25t0.578 0.25q0.25 0.219 0.25 0.578t-0.25 0.578z";
const ICON_PATHS = {
none: "",
......@@ -8439,7 +8441,7 @@ function usePageHeadButtons(navigationBar) {
const fonts = Object.create(null);
buttons.forEach((btn) => {
if (btn.fontSrc && !btn.fontFamily) {
const fontSrc = getRealPath(btn.fontSrc);
const fontSrc = getRealPath$1(btn.fontSrc);
let fontFamily = fonts[fontSrc];
if (!fontFamily) {
fontFamily = `font${Date.now()}`;
......@@ -9243,4 +9245,4 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
]);
}
_sfc_main.render = _sfc_render;
export {_sfc_main$1 as AsyncErrorComponent, _sfc_main as AsyncLoadingComponent, _sfc_main$p as Audio, _sfc_main$o as Canvas, _sfc_main$n as Checkbox, _sfc_main$m as CheckboxGroup, _sfc_main$l as Editor, _sfc_main$k as Form, index$1 as Icon, _sfc_main$j as Image, _sfc_main$i as Input, _sfc_main$h as Label, _sfc_main$g as MovableView, _sfc_main$f as Navigator, index as PageComponent, _sfc_main$e as Progress, _sfc_main$d as Radio, _sfc_main$c as RadioGroup, _sfc_main$b as ResizeSensor, _sfc_main$a as RichText, _sfc_main$9 as ScrollView, _sfc_main$8 as Slider, _sfc_main$7 as SwiperItem, _sfc_main$6 as Switch, _sfc_main$5 as Text, _sfc_main$4 as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, _sfc_main$3 as View, addInterceptor, arrayBufferToBase64, base64ToArrayBuffer, canIUse, createIntersectionObserver, createSelectorQuery, getApp$1 as getApp, getCurrentPages$1 as getCurrentPages, getImageInfo, getRealPath$1 as getRealPath, getSystemInfo, getSystemInfoSync, makePhoneCall, navigateBack, navigateTo, openDocument, index$2 as plugin, promiseInterceptor, reLaunch, redirectTo, removeInterceptor, switchTab, uni$1 as uni, upx2px};
export {_sfc_main$1 as AsyncErrorComponent, _sfc_main as AsyncLoadingComponent, _sfc_main$p as Audio, _sfc_main$o as Canvas, _sfc_main$n as Checkbox, _sfc_main$m as CheckboxGroup, _sfc_main$l as Editor, _sfc_main$k as Form, index$1 as Icon, _sfc_main$j as Image, _sfc_main$i as Input, _sfc_main$h as Label, _sfc_main$g as MovableView, _sfc_main$f as Navigator, index as PageComponent, _sfc_main$e as Progress, _sfc_main$d as Radio, _sfc_main$c as RadioGroup, _sfc_main$b as ResizeSensor, _sfc_main$a as RichText, _sfc_main$9 as ScrollView, _sfc_main$8 as Slider, _sfc_main$7 as SwiperItem, _sfc_main$6 as Switch, _sfc_main$5 as Text, _sfc_main$4 as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, _sfc_main$3 as View, addInterceptor, arrayBufferToBase64, base64ToArrayBuffer, canIUse, createIntersectionObserver, createSelectorQuery, getApp$1 as getApp, getCurrentPages$1 as getCurrentPages, getImageInfo, getRealPath, getSystemInfo, getSystemInfoSync, makePhoneCall, navigateBack, navigateTo, openDocument, index$2 as plugin, promiseInterceptor, reLaunch, redirectTo, removeInterceptor, switchTab, uni$1 as uni, upx2px};
import { computed, defineComponent, Ref, ref } from 'vue'
import { isArray } from '@vue/shared'
import { Input } from '@dcloudio/uni-components'
import { getRealPath } from '@dcloudio/uni-platform'
import { ICON_PATH_SEARCH, createSvgIconVNode } from '@dcloudio/uni-core'
import { usePageMeta } from '../../plugin/provide'
import {
......@@ -9,7 +10,6 @@ import {
} from './transparent'
import { updateStyle } from '../../../helpers/dom'
import { getRealPath } from '../../../helpers/getRealPath'
const ICON_PATH_BACK =
'M21.781 7.844l-9.063 8.594 9.063 8.594q0.25 0.25 0.25 0.609t-0.25 0.578q-0.25 0.25-0.578 0.25t-0.578-0.25l-9.625-9.125q-0.156-0.125-0.203-0.297t-0.047-0.359q0-0.156 0.047-0.328t0.203-0.297l9.625-9.125q0.25-0.25 0.578-0.25t0.578 0.25q0.25 0.219 0.25 0.578t-0.25 0.578z'
......
......@@ -26,6 +26,13 @@ export function isPage(vm: ComponentPublicInstance) {
return vm.$options.mpType === 'page'
}
function normalizeRoute(path: string) {
if (path.indexOf('/') === 0) {
return path.substr(1)
}
return path
}
function initPublicPage(route: RouteLocationNormalizedLoaded) {
if (!route) {
const { path } = __uniRoutes[0]
......@@ -34,7 +41,7 @@ function initPublicPage(route: RouteLocationNormalizedLoaded) {
return {
id,
path: route.path,
route: route.meta.pagePath,
route: normalizeRoute((route.meta.route as string) || route.path),
fullPath: route.meta.isEntry ? route.meta.pagePath : route.fullPath,
options: {}, // $route.query
meta: usePageMeta(),
......@@ -44,7 +51,7 @@ function initPublicPage(route: RouteLocationNormalizedLoaded) {
export function initPage(vm: ComponentPublicInstance) {
currentPages.push(vm as Page.PageInstance)
const route = vm.$route
;(vm as any).__page__ = initPublicPage(route)
;(vm as any).$page = initPublicPage(route)
}
// TODO
......
export * from './getRealPath'
......@@ -43,6 +43,10 @@ export default defineConfig({
find: '@dcloudio/uni-components',
replacement: resolve('../uni-components/src/index.ts'),
},
{
find: '@dcloudio/uni-platform',
replacement: resolve('./src/platform/index.ts'),
},
],
},
plugins: [
......
import { createPublicFileFilter } from '../src/utils'
describe('static', () => {
test('filter', () => {
const filter = createPublicFileFilter('/')
expect(filter('logo.png')).toBe(false)
expect(filter('/static/logo.png')).toBe(true)
expect(filter('/static/test/logo.png')).toBe(true)
expect(filter('/uni_modules/fxy-components/logo.png')).toBe(false)
expect(filter('/uni_modules/fxy-components/static/logo.png')).toBe(true)
expect(filter('/uni_modules/fxy-components/static/test/logo.png')).toBe(
true
)
})
})
......@@ -27,16 +27,18 @@
"fs-extra": "^9.0.1",
"jsonc-parser": "^3.0.0",
"magic-string": "^0.25.7",
"mime": "^2.5.2",
"rollup-plugin-copy": "^3.4.0",
"slash": "^3.0.0"
},
"peerDependencies": {
"@dcloudio/uni-cli-shared": "^3.0.0",
"@dcloudio/uni-shared": "^3.0.0",
"@vue/shared": "^3.0.7",
"vite": "^2.1.1"
"@vue/shared": "^3.0.10",
"vite": "^2.1.5"
},
"devDependencies": {
"@types/mime": "^2.0.3",
"@types/sass": "^1.16.0"
},
"uni-app": {
......
import path from 'path'
import { Plugin } from 'vite'
import copy from 'rollup-plugin-copy'
import { PUBLIC_DIR } from '@dcloudio/uni-cli-shared'
import { VitePluginUniResolvedOptions } from '../..'
export function uniCopyPlugin({
......@@ -11,11 +12,11 @@ export function uniCopyPlugin({
return copy({
targets: [
{
src: path.resolve(inputDir, 'static'),
src: path.resolve(inputDir, PUBLIC_DIR),
dest: outputDir,
},
{
src: path.resolve(inputDir, 'uni_modules/*/static'),
src: path.resolve(inputDir, 'uni_modules/*/' + PUBLIC_DIR),
dest: outputDir,
rename: (name, extension, fullPath) => {
return path.relative(inputDir, fullPath)
......
......@@ -14,6 +14,7 @@ import { uniPagesJsonPlugin } from './pagesJson'
import { uniManifestJsonPlugin } from './manifestJson'
import { uniPageVuePlugin } from './pageVue'
import { uniCopyPlugin } from './copy'
import { uniStaticPlugin } from './static'
const debugPlugin = debug('uni:plugin')
......@@ -93,6 +94,7 @@ export function resolvePlugins(
)
addPlugin(plugins, uniPageVuePlugin({ command }), 'vite:vue')
addPlugin(plugins, uniJsonPlugin(options), 'vite:json', 'pre')
addPlugin(plugins, uniStaticPlugin(options, config), 'vite:asset', 'pre')
if (command === 'build') {
addPlugin(plugins, uniCopyPlugin(options), plugins.length)
}
......
......@@ -152,6 +152,10 @@ function normalizePagesRoute(pagesJson: UniApp.PagesJson): PageRouteOptions[] {
pageOptions.style
)
if (isEntry) {
;(meta as any).route = pageOptions.path
}
return {
name,
path: pageOptions.path,
......
import debug from 'debug'
import { Plugin, ResolvedConfig } from 'vite'
import { cleanUrl } from '@dcloudio/uni-cli-shared'
import { UniPluginFilterOptions } from '.'
import { createPublicFileFilter } from '../../utils'
const debugStatic = debug('uni:static')
/**
* 提供static等目录静态资源加载
* @param _options
* @param config
* @returns
*/
export function uniStaticPlugin(
_options: UniPluginFilterOptions,
config: ResolvedConfig
): Plugin {
const filter = createPublicFileFilter()
return {
name: 'vite:uni-static',
resolveId(id) {
if (!config.assetsInclude(cleanUrl(id))) {
return
}
const publicFile = filter(id)
if (publicFile) {
debugStatic(id)
return id
}
},
async load(id) {
if (!config.assetsInclude(cleanUrl(id))) {
return
}
if (filter(id)) {
return `export default ${JSON.stringify(fileToUrl(id, config))}`
}
},
}
}
function fileToUrl(id: string, config: ResolvedConfig) {
return config.base + id.slice(1)
}
import { Plugin } from 'vite'
import { VitePluginUniResolvedOptions } from '..'
import { serveEasycom } from './easycom'
import { serveStatic } from './static'
export function createConfigureServer(
options: VitePluginUniResolvedOptions
......@@ -8,5 +9,8 @@ export function createConfigureServer(
return function (server) {
options.devServer = server
serveEasycom(server, options)
return () => {
serveStatic(server, options)
}
}
}
import fs, { Stats } from 'fs'
import url from 'url'
import mime from 'mime/lite'
import { IncomingMessage, OutgoingHttpHeaders, ServerResponse } from 'http'
function normalizeFile(filename: string, isEtag: boolean) {
const stats = fs.statSync(filename)
return {
stats,
headers: normalizeHeaders(filename, stats, isEtag),
}
}
function normalizeHeaders(filename: string, stats: Stats, isEtag: boolean) {
const headers: OutgoingHttpHeaders = {
'Content-Length': stats.size,
'Content-Type': mime.getType(filename) || '',
'Last-Modified': stats.mtime.toUTCString(),
}
if (isEtag) {
headers['ETag'] = `W/"${stats.size}-${stats.mtime.getTime()}"`
}
return headers
}
function send(
req: IncomingMessage,
res: ServerResponse,
filename: string,
stats: Stats,
headers: OutgoingHttpHeaders
) {
let code = 200
headers = { ...headers }
const opts: {
end?: number
start?: number
} = {}
for (const key in headers) {
const value = res.getHeader(key)
if (value) {
headers[key] = value
}
}
if (res.getHeader('content-type')) {
headers['Content-Type'] = res.getHeader('content-type')
}
if (req.headers.range) {
code = 206
const [x, y] = req.headers.range.replace('bytes=', '').split('-')
const end = (opts.end = parseInt(y, 10) || stats.size - 1)
const start = (opts.start = parseInt(x, 10) || 0)
if (start >= stats.size || end >= stats.size) {
res.setHeader('Content-Range', `bytes */${stats.size}`)
res.statusCode = 416
return res.end()
}
headers['Content-Range'] = `bytes ${start}-${end}/${stats.size}`
headers['Content-Length'] = end - start + 1
headers['Accept-Ranges'] = 'bytes'
}
res.writeHead(code, headers)
fs.createReadStream(filename, opts).pipe(res)
}
interface UniStaticMiddlewareOptions {
etag: boolean
resolve: (pathname: string) => string | void
}
type NextHandler = () => void | Promise<void>
export function uniStaticMiddleware(opts: UniStaticMiddlewareOptions) {
const isEtag = !!opts.etag
return function (
req: IncomingMessage,
res: ServerResponse,
next: NextHandler
) {
const pathname = url.parse(req.url!).pathname
if (!pathname) {
return next()
}
const filename = opts.resolve(pathname)
if (!filename) {
return next()
}
const data = normalizeFile(filename, isEtag)
if (!data) {
return next()
}
if (isEtag && req.headers['if-none-match'] === data.headers['ETag']) {
res.writeHead(304)
return res.end()
}
return send(req, res, filename, data.stats, data.headers)
}
}
import fs from 'fs'
import path from 'path'
import debug from 'debug'
import { ViteDevServer } from 'vite'
import { isImportRequest } from '@dcloudio/uni-cli-shared'
import { VitePluginUniResolvedOptions } from '..'
import { uniStaticMiddleware } from './middlewares/static'
import { createPublicFileFilter } from '../utils'
const debugStatic = debug('uni:static')
/**
* devServer时提供static等目录的静态资源服务
* @param server
* @param param
*/
export const serveStatic = (
server: ViteDevServer,
{ inputDir }: VitePluginUniResolvedOptions
) => {
const filter = createPublicFileFilter()
const serve = uniStaticMiddleware({
etag: true,
resolve(pathname) {
if (!filter(pathname)) {
return
}
const filename = path.join(inputDir, pathname)
if (fs.existsSync(filename)) {
debugStatic(filename, 'success')
return filename
} else {
debugStatic(filename, 'fail')
}
},
})
server.middlewares.use((req, res, next) => {
// skip import request
if (isImportRequest(req.url!)) {
return next()
}
return serve(req, res, next)
})
}
import path from 'path'
import { createFilter } from '@rollup/pluginutils'
import { PUBLIC_DIR } from '@dcloudio/uni-cli-shared'
export function createPublicFileFilter(base: string = '/') {
const publicDir = path.join(base, PUBLIC_DIR + '/**/*')
const uniModulesDir = path.join(base, 'uni_modules/*/' + PUBLIC_DIR + '/**/*')
return createFilter([publicDir, uniModulesDir])
}
export * from './filter'
export * from './define'
export * from './pagesJson'
import { ElementNode, NodeTransform } from '@vue/compiler-core'
import { CompilerOptions } from '@vue/compiler-sfc'
import { CompilerOptions, SFCTemplateCompileOptions } from '@vue/compiler-sfc'
import { isNativeTag } from '@dcloudio/uni-shared'
const transform: NodeTransform = (node) => {
const transform: NodeTransform = (node, ctx) => {
if (
process.env.UNI_PLATFORM !== 'mp-weixin' &&
(node as ElementNode).tag === 'match-media'
......@@ -17,3 +17,26 @@ export const uniVueCompilerOptions: CompilerOptions = {
isNativeTag,
nodeTransforms: [transform],
}
export const uniVueTransformAssetUrls: SFCTemplateCompileOptions['transformAssetUrls'] = {
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 const uniVueTemplateOptions: Partial<SFCTemplateCompileOptions> = {
compilerOptions: uniVueCompilerOptions,
transformAssetUrls: uniVueTransformAssetUrls,
}
......@@ -27,7 +27,10 @@
"rootDir": ".",
"paths": {
"@dcloudio/*": ["packages/*/src"],
"@dcloudio/uni-mp-polyfill": ["packages/uni-mp-core/src/runtime/polyfill"]
"@dcloudio/uni-mp-polyfill": [
"packages/uni-mp-core/src/runtime/polyfill"
],
"@dcloudio/uni-platform": ["packages/uni-h5/src/platform/index.ts"]
}
},
"include": [
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册