feat(vite-plugins): 添加 vant-touch-emulator 和 eruda 脚本支持
This commit is contained in:
70
index.html
70
index.html
@@ -11,40 +11,6 @@
|
|||||||
name="viewport"
|
name="viewport"
|
||||||
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
|
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
|
||||||
/>
|
/>
|
||||||
<script>
|
|
||||||
window.addEventListener('DOMContentLoaded', function () {
|
|
||||||
window.ontouchstart = function () {};
|
|
||||||
window.ontouchend = function () {};
|
|
||||||
});
|
|
||||||
|
|
||||||
window.onloadX = function () {
|
|
||||||
// 禁止双指缩放
|
|
||||||
document.addEventListener('touchstart', function (event) {
|
|
||||||
if (event.touches.length > 1) {
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 禁止双击放大
|
|
||||||
var lastTouchEnd = 0;
|
|
||||||
document.addEventListener(
|
|
||||||
'touchend',
|
|
||||||
function (event) {
|
|
||||||
var now = new Date().getTime();
|
|
||||||
if (now - lastTouchEnd <= 300) {
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
|
||||||
lastTouchEnd = now;
|
|
||||||
},
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
|
|
||||||
// 禁止手势事件
|
|
||||||
document.addEventListener('gesturestart', function (event) {
|
|
||||||
event.preventDefault();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<meta name="color-scheme" content="light dark" />
|
<meta name="color-scheme" content="light dark" />
|
||||||
<meta name="format-detection" content="telephone=no" />
|
<meta name="format-detection" content="telephone=no" />
|
||||||
@@ -132,7 +98,40 @@
|
|||||||
<!-- <script src="https://testingcf.jsdelivr.net/npm/@vant/touch-emulator/dist/index.min.js"></script> -->
|
<!-- <script src="https://testingcf.jsdelivr.net/npm/@vant/touch-emulator/dist/index.min.js"></script> -->
|
||||||
<!-- .min.js 是 jsDelivr 的特殊处理 -->
|
<!-- .min.js 是 jsDelivr 的特殊处理 -->
|
||||||
<!-- <script src="https://unpkg.luckincdn.com/@vant/touch-emulator@1.4.0/dist/index.js"></script> -->
|
<!-- <script src="https://unpkg.luckincdn.com/@vant/touch-emulator@1.4.0/dist/index.js"></script> -->
|
||||||
</body>
|
<script>
|
||||||
|
window.addEventListener('DOMContentLoaded', function () {
|
||||||
|
window.ontouchstart = function () {};
|
||||||
|
window.ontouchend = function () {};
|
||||||
|
});
|
||||||
|
|
||||||
|
window.onloadX = function () {
|
||||||
|
// 禁止双指缩放
|
||||||
|
document.addEventListener('touchstart', function (event) {
|
||||||
|
if (event.touches.length > 1) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 禁止双击放大
|
||||||
|
var lastTouchEnd = 0;
|
||||||
|
document.addEventListener(
|
||||||
|
'touchend',
|
||||||
|
function (event) {
|
||||||
|
var now = new Date().getTime();
|
||||||
|
if (now - lastTouchEnd <= 300) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
lastTouchEnd = now;
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
// 禁止手势事件
|
||||||
|
document.addEventListener('gesturestart', function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
</script>
|
||||||
<script>
|
<script>
|
||||||
(function (d) {
|
(function (d) {
|
||||||
var config = {
|
var config = {
|
||||||
@@ -163,4 +162,5 @@
|
|||||||
s.parentNode.insertBefore(tk, s);
|
s.parentNode.insertBefore(tk, s);
|
||||||
}); /* (document) */
|
}); /* (document) */
|
||||||
</script>
|
</script>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -10,17 +10,4 @@ export function install({ app }: { app: import('vue').App<Element> }) {
|
|||||||
// 2. 显示全局错误提示
|
// 2. 显示全局错误提示
|
||||||
// 3. 进行错误分析和处理
|
// 3. 进行错误分析和处理
|
||||||
};
|
};
|
||||||
|
|
||||||
// if (import.meta.env.MODE === 'development' && '1' === ('2' as never)) {
|
|
||||||
// // TODO: https://github.com/hu3dao/vite-plugin-debug/
|
|
||||||
// // https://eruda.liriliri.io/zh/docs/#快速上手
|
|
||||||
// import('eruda').then(({ default: eruda }) => {
|
|
||||||
// eruda.init({
|
|
||||||
// defaults: {
|
|
||||||
// transparency: 0.9,
|
|
||||||
// },
|
|
||||||
// })
|
|
||||||
// /* eruda.show(); */
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,73 @@ function IndexHtmlPlugin(): PluginOption {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ___(): PluginOption {
|
||||||
|
// https://github.com/hu3dao/vite-plugin-debug/blob/2935025e8ce082b9a5aef04766bcae3e996b3e55/src/index.ts
|
||||||
|
return {
|
||||||
|
name: 'vant-touch-emulator-online',
|
||||||
|
apply: 'build',
|
||||||
|
transformIndexHtml(html) {
|
||||||
|
return {
|
||||||
|
html,
|
||||||
|
tags: [
|
||||||
|
{
|
||||||
|
tag: 'script',
|
||||||
|
attrs: {
|
||||||
|
src: 'https://testingcf.jsdelivr.net/npm/@vant/touch-emulator/dist/index.min.js',
|
||||||
|
// 这里的 `.min.js` 是 jsDelivr 的特殊处理
|
||||||
|
// src: 'https://unpkg.luckincdn.com/@vant/touch-emulator@1.4.0/dist/index.js',
|
||||||
|
},
|
||||||
|
injectTo: 'body',
|
||||||
|
},
|
||||||
|
|
||||||
|
// >>>>> eruda
|
||||||
|
|
||||||
|
{
|
||||||
|
tag: 'script',
|
||||||
|
attrs: {
|
||||||
|
src: 'https://testingcf.jsdelivr.net/npm/eruda/eruda.js',
|
||||||
|
},
|
||||||
|
injectTo: 'body',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tag: 'script',
|
||||||
|
children: `eruda.init();`,
|
||||||
|
injectTo: 'body',
|
||||||
|
},
|
||||||
|
// https://eruda.liriliri.io/zh/docs/#快速上手
|
||||||
|
// import('eruda').then(({ default: eruda }) => {
|
||||||
|
// eruda.init({
|
||||||
|
// defaults: {
|
||||||
|
// transparency: 0.9,
|
||||||
|
// },
|
||||||
|
// })
|
||||||
|
// /* eruda.show(); */
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
// <<<<<
|
||||||
|
|
||||||
|
// >>>>> vConsole
|
||||||
|
{
|
||||||
|
tag: 'script',
|
||||||
|
attrs: {
|
||||||
|
src: 'https://cdn.jsdelivr.net/npm/vconsole@latest/dist/vconsole.min.js',
|
||||||
|
},
|
||||||
|
injectTo: 'body',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tag: 'script',
|
||||||
|
children: `new window.VConsole();`,
|
||||||
|
injectTo: 'body',
|
||||||
|
},
|
||||||
|
// <<<<<
|
||||||
|
],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function loadPlugin(_configEnv: ConfigEnv): PluginOption {
|
export function loadPlugin(_configEnv: ConfigEnv): PluginOption {
|
||||||
|
// return [___()];
|
||||||
const env = loadEnv(_configEnv.mode, process.cwd());
|
const env = loadEnv(_configEnv.mode, process.cwd());
|
||||||
if (env.VITE_BUILD_MINIFY === 'true') return IndexHtmlPlugin();
|
if (env.VITE_BUILD_MINIFY === 'true') return IndexHtmlPlugin();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user