feat: 更改自定义参数引入方式

This commit is contained in:
imsyy 2023-08-14 11:46:28 +08:00
parent c5b0b44fed
commit 2496110d5d
5 changed files with 493 additions and 675 deletions

4
.env
View File

@ -7,10 +7,6 @@ VITE_SITE_URL = "imsyy.top"
VITE_SITE_LOGO = "/images/icon/favicon.ico" VITE_SITE_LOGO = "/images/icon/favicon.ico"
VITE_SITE_APPLE_LOGO = "/images/logo/apple-touch-icon.png" VITE_SITE_APPLE_LOGO = "/images/logo/apple-touch-icon.png"
# 百度统计
## 若不需要,请设为空即可
VITE_SITE_BAIDUTONGJI = "14e9f35ff8bc67fd4bcb5f07a6e6655a"
# 简介文本 # 简介文本
VITE_DESC_HELLO = "Hello World !" VITE_DESC_HELLO = "Hello World !"
VITE_DESC_TEXT = "一个建立于 21 世纪的小站,存活于互联网的边缘" VITE_DESC_TEXT = "一个建立于 21 世纪的小站,存活于互联网的边缘"

View File

@ -6,15 +6,15 @@
<meta http-equiv="Access-Control-Allow-Origin" content="*"> <meta http-equiv="Access-Control-Allow-Origin" content="*">
<!-- <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests"> --> <!-- <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests"> -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" href="<%- logo %>"> <link rel="icon" href="%VITE_SITE_LOGO%">
<link rel="apple-touch-icon" href="<%- appleLogo %>" /> <link rel="apple-touch-icon" href="%VITE_SITE_APPLE_LOGO%" />
<link rel="bookmark" href="<%- appleLogo %>" /> <link rel="bookmark" href="%VITE_SITE_APPLE_LOGO%" />
<link rel="apple-touch-icon-precomposed" sizes="200x200" href="<%- appleLogo %>" /> <link rel="apple-touch-icon-precomposed" sizes="200x200" href="%VITE_SITE_APPLE_LOGO%" />
<meta name="description" content="<%- description %>" /> <meta name="description" content="%VITE_SITE_DES%" />
<meta name="keywords" content="<%- keywords %>" /> <meta name="keywords" content="%VITE_SITE_KEYWORDS%" />
<meta name="author" content="<%- author %>" /> <meta name="author" content="%VITE_SITE_ANTHOR%" />
<meta name="theme-color" content="#424242" /> <meta name="theme-color" content="#424242" />
<title><%- title %></title> <title>%VITE_SITE_NAME%</title>
<!-- HarmonyOS Sans --> <!-- HarmonyOS Sans -->
<!-- 本站 CDN 已开启防盗链,非本站域名不可访问,请更改链接为下方内容,否则自定义字体将失效 --> <!-- 本站 CDN 已开启防盗链,非本站域名不可访问,请更改链接为下方内容,否则自定义字体将失效 -->
<!-- https://s1.hdslb.com/bfs/static/jinkela/long/font/regular.css --> <!-- https://s1.hdslb.com/bfs/static/jinkela/long/font/regular.css -->
@ -26,18 +26,6 @@
window.location.href = window.location.href =
"https://support.dmeng.net/upgrade-your-browser.html?referrer=" + encodeURIComponent(window.location.href) "https://support.dmeng.net/upgrade-your-browser.html?referrer=" + encodeURIComponent(window.location.href)
</script> </script>
<% if (tongji) { %>
<!-- 百度统计 -->
<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?<%- tongji %>";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
<% } %>
</head> </head>
<body class="loading"> <body class="loading">
@ -52,7 +40,7 @@
<div class="inner three"></div> <div class="inner three"></div>
</div> </div>
<div class="loading-word"> <div class="loading-word">
<p class="loading-title" id="loading-title"><%- title %></p> <p class="loading-title" id="loading-title">%VITE_SITE_NAME%</p>
<span id="loading-text">加载中</span> <span id="loading-text">加载中</span>
</div> </div>
</div> </div>

View File

@ -20,20 +20,20 @@
"pinia": "^2.0.23", "pinia": "^2.0.23",
"pinia-plugin-persistedstate": "^3.0.0", "pinia-plugin-persistedstate": "^3.0.0",
"swiper": "^9.3.2", "swiper": "^9.3.2",
"terser": "^5.16.1", "vue": "^3.3.4",
"vue": "^3.2.37",
"vue3-aplayer": "^1.7.3" "vue3-aplayer": "^1.7.3"
}, },
"devDependencies": { "devDependencies": {
"@vicons/fa": "^0.12.0", "@vicons/fa": "^0.12.0",
"@vicons/material": "^0.12.0", "@vicons/material": "^0.12.0",
"@vicons/utils": "^0.1.4", "@vicons/utils": "^0.1.4",
"@vitejs/plugin-vue": "^3.1.0", "@vitejs/plugin-vue": "^4.2.3",
"sass": "^1.55.0", "sass": "^1.55.0",
"terser": "^5.16.1",
"unplugin-auto-import": "^0.11.2", "unplugin-auto-import": "^0.11.2",
"unplugin-vue-components": "^0.22.8", "unplugin-vue-components": "^0.22.8",
"vite": "^3.1.0", "vite": "^4.4.5",
"vite-plugin-html": "^3.2.0", "vite-plugin-compression": "^0.5.1",
"vite-plugin-pwa": "^0.14.1" "vite-plugin-pwa": "^0.14.1"
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,27 +1,15 @@
import { import { defineConfig, loadEnv } from "vite";
defineConfig, import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
loadEnv import { resolve } from "path";
} from 'vite'; import { VitePWA } from "vite-plugin-pwa";
import vue from '@vitejs/plugin-vue'; import vue from "@vitejs/plugin-vue";
import AutoImport from 'unplugin-auto-import/vite' import AutoImport from "unplugin-auto-import/vite";
import Components from 'unplugin-vue-components/vite' import Components from "unplugin-vue-components/vite";
import { import viteCompression from "vite-plugin-compression";
ElementPlusResolver
} from 'unplugin-vue-components/resolvers'
import {
createHtmlPlugin
} from 'vite-plugin-html';
import {
resolve
} from 'path';
import {
VitePWA
} from 'vite-plugin-pwa';
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default ({ export default ({ mode }) =>
mode defineConfig({
}) => defineConfig({
plugins: [ plugins: [
vue(), vue(),
AutoImport({ AutoImport({
@ -30,106 +18,103 @@ export default ({
Components({ Components({
resolvers: [ElementPlusResolver()], resolvers: [ElementPlusResolver()],
}), }),
createHtmlPlugin({
minify: true,
inject: {
data: {
logo: loadEnv(mode, process.cwd()).VITE_SITE_LOGO,
appleLogo: loadEnv(mode, process.cwd()).VITE_SITE_APPLE_LOGO,
title: loadEnv(mode, process.cwd()).VITE_SITE_NAME,
author: loadEnv(mode, process.cwd()).VITE_SITE_ANTHOR,
keywords: loadEnv(mode, process.cwd()).VITE_SITE_KEYWORDS,
description: loadEnv(mode, process.cwd()).VITE_SITE_DES,
tongji: loadEnv(mode, process.cwd()).VITE_SITE_BAIDUTONGJI,
},
},
}),
VitePWA({ VitePWA({
registerType: 'autoUpdate', registerType: "autoUpdate",
workbox: { workbox: {
skipWaiting: true, skipWaiting: true,
clientsClaim: true, clientsClaim: true,
runtimeCaching: [{ runtimeCaching: [
{
urlPattern: /(.*?)\.(js|css|woff2|woff|ttf)/, // js / css 静态资源缓存 urlPattern: /(.*?)\.(js|css|woff2|woff|ttf)/, // js / css 静态资源缓存
handler: 'CacheFirst', handler: "CacheFirst",
options: { options: {
cacheName: 'js-css-cache', cacheName: "js-css-cache",
}, },
}, },
{ {
urlPattern: /(.*?)\.(png|jpe?g|svg|gif|bmp|psd|tiff|tga|eps)/, // 图片缓存 urlPattern: /(.*?)\.(png|jpe?g|svg|gif|bmp|psd|tiff|tga|eps)/, // 图片缓存
handler: 'CacheFirst', handler: "CacheFirst",
options: { options: {
cacheName: 'image-cache', cacheName: "image-cache",
}, },
}, },
], ],
}, },
manifest: { manifest: {
"name": loadEnv(mode, process.cwd()).VITE_SITE_NAME, name: loadEnv(mode, process.cwd()).VITE_SITE_NAME,
"short_name": loadEnv(mode, process.cwd()).VITE_SITE_NAME, short_name: loadEnv(mode, process.cwd()).VITE_SITE_NAME,
"description": loadEnv(mode, process.cwd()).VITE_SITE_DES, description: loadEnv(mode, process.cwd()).VITE_SITE_DES,
"display": "standalone", display: "standalone",
"start_url": "/", start_url: "/",
"theme_color": "#424242", theme_color: "#424242",
"background_color": "#424242", background_color: "#424242",
"icons": [{ icons: [
"src": "/images/icon/48.png", {
"sizes": "48x48", src: "/images/icon/48.png",
"type": "image/png" sizes: "48x48",
}, { type: "image/png",
"src": "/images/icon/72.png", },
"sizes": "72x72", {
"type": "image/png" src: "/images/icon/72.png",
}, { sizes: "72x72",
"src": "/images/icon/96.png", type: "image/png",
"sizes": "96x96", },
"type": "image/png" {
}, { src: "/images/icon/96.png",
"src": "/images/icon/128.png", sizes: "96x96",
"sizes": "128x128", type: "image/png",
"type": "image/png" },
}, { {
"src": "/images/icon/144.png", src: "/images/icon/128.png",
"sizes": "144x144", sizes: "128x128",
"type": "image/png" type: "image/png",
}, { },
"src": "/images/icon/192.png", {
"sizes": "192x192", src: "/images/icon/144.png",
"type": "image/png" sizes: "144x144",
}, { type: "image/png",
"src": "/images/icon/512.png", },
"sizes": "512x512", {
"type": "image/png" src: "/images/icon/192.png",
}] sizes: "192x192",
} type: "image/png",
},
{
src: "/images/icon/512.png",
sizes: "512x512",
type: "image/png",
},
],
},
}), }),
viteCompression(),
], ],
server: { server: {
port: "3000", port: "3000",
hmr: true, hmr: true,
}, },
resolve: { resolve: {
alias: [{ alias: [
find: '@', {
find: "@",
replacement: resolve(__dirname, "src"), replacement: resolve(__dirname, "src"),
}, ] },
],
}, },
css: { css: {
preprocessorOptions: { preprocessorOptions: {
scss: { scss: {
charset: false, charset: false,
additionalData: `@import "./src/style/global.scss";` additionalData: `@import "./src/style/global.scss";`,
} },
} },
}, },
build: { build: {
minify: 'terser', minify: "terser",
terserOptions: { terserOptions: {
compress: { compress: {
// 生产环境时移除 console pure_funcs: ["console.log"],
pure_funcs: ['console.log'],
}, },
}, },
}, },
}) });