Skip to content

Commit

Permalink
chore: HTML 中增加 version meta
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Feb 3, 2024
1 parent 869b81d commit 124d07e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<head>
<meta charset="UTF-8" />
<meta name="version" content="__SUB_STORE_FRONT_END_VERSION__">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<!-- <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-store-front-end",
"version": "2.14.129",
"version": "2.14.130",
"private": true,
"scripts": {
"dev": "vite --host",
Expand Down
14 changes: 13 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,28 @@ import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
import viteCompression from 'vite-plugin-compression';
import { VitePWA } from 'vite-plugin-pwa';

const version = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf-8')).version.trim()

const alias: Record<string, string> = {
'@': path.resolve(__dirname, 'src'),
vue: 'vue/dist/vue.esm-bundler.js',
};

const htmlPlugin = () => {
return {
name: "html-transform",
transformIndexHtml(html: string) {
return html.replace(/__SUB_STORE_FRONT_END_VERSION__/g, version);
},
};
};

const viteConfig = defineConfig((mode: ConfigEnv) => {
const env = loadEnv(mode.mode, process.cwd());

return {
plugins: [
htmlPlugin(),
vue(),
createStyleImportPlugin({
// resolves: [NutuiResolve()],
Expand Down Expand Up @@ -172,7 +184,7 @@ const viteConfig = defineConfig((mode: ConfigEnv) => {
__VUE_I18N_FULL_INSTALL__: true,
__VUE_I18N_LEGACY_API__: false,
__INTLIFY_PROD_DEVTOOLS__: false,
'import.meta.env.PACKAGE_VERSION': JSON.stringify(JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf-8')).version.trim()),
'import.meta.env.PACKAGE_VERSION': JSON.stringify(version),
},
};
});
Expand Down

0 comments on commit 124d07e

Please sign in to comment.