From e5b02a9616bd5b8f922bdce35e767e92c635c5d8 Mon Sep 17 00:00:00 2001 From: Yuriy Evdokimov Date: Wed, 13 Dec 2023 16:45:53 +0500 Subject: [PATCH] auto add analytics for build --- index.html | 1 - package-lock.json | 35 ++++++++++++++++++++++++++++++++--- package.json | 9 +++++++-- vite.config.ts | 40 +++++++++++++++++++++++++++++++++++----- 4 files changed, 74 insertions(+), 11 deletions(-) diff --git a/index.html b/index.html index f2d6d9a..d03d427 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,6 @@ - Pinyin dictation diff --git a/package-lock.json b/package-lock.json index 8d17e13..87c07a0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pinyindictation", - "version": "1.1.0", + "version": "1.2.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pinyindictation", - "version": "1.1.0", + "version": "1.2.1", "dependencies": { "bootstrap": "^5.3.2", "react": "^18.2.0", @@ -14,6 +14,7 @@ "react-dom": "^18.2.0" }, "devDependencies": { + "@types/node": "^20.10.4", "@types/react": "^18.2.15", "@types/react-dom": "^18.2.7", "@typescript-eslint/eslint-plugin": "^6.0.0", @@ -23,7 +24,8 @@ "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-refresh": "^0.4.3", "typescript": "^5.0.2", - "vite": "^4.4.5" + "vite": "^4.4.5", + "vite-plugin-html-config": "^1.0.11" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -1019,6 +1021,15 @@ "integrity": "sha512-RbSSoHliUbnXj3ny0CNFOoxrIDV6SUGyStHsvDqosw6CkdPV8TtWGlfecuK4ToyMEAql6pzNxgCFKanovUzlgQ==", "dev": true }, + "node_modules/@types/node": { + "version": "20.10.4", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.4.tgz", + "integrity": "sha512-D08YG6rr8X90YB56tSIuBaddy/UXAA9RKJoFvrsnogAum/0pmjkgi4+2nx96A330FmioegBWmEYQ+syqCFaveg==", + "dev": true, + "dependencies": { + "undici-types": "~5.26.4" + } + }, "node_modules/@types/prop-types": { "version": "15.7.6", "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.6.tgz", @@ -3011,6 +3022,12 @@ "react": ">=15.0.0" } }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true + }, "node_modules/update-browserslist-db": { "version": "1.0.13", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.13.tgz", @@ -3105,6 +3122,18 @@ } } }, + "node_modules/vite-plugin-html-config": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/vite-plugin-html-config/-/vite-plugin-html-config-1.0.11.tgz", + "integrity": "sha512-hUybhgI+/LQQ5q6xoMMsTvI4PBuQD/Wv6Z1vtDPVWjanS8weCIexXuLLYNGD/93f0v8W2hpNfXpmxgpZMahJ0g==", + "dev": true, + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "vite": ">=2.0.0" + } + }, "node_modules/warning": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/warning/-/warning-4.0.3.tgz", diff --git a/package.json b/package.json index 074499c..d3891f6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,9 @@ { "name": "pinyindictation", - "author": {"email": "rurik19@yandex.ru", "name": "Юрий Евдокимов"}, + "author": { + "email": "rurik19@yandex.ru", + "name": "Юрий Евдокимов" + }, "private": true, "version": "1.2.1", "type": "module", @@ -17,6 +20,7 @@ "react-dom": "^18.2.0" }, "devDependencies": { + "@types/node": "^20.10.4", "@types/react": "^18.2.15", "@types/react-dom": "^18.2.7", "@typescript-eslint/eslint-plugin": "^6.0.0", @@ -26,6 +30,7 @@ "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-refresh": "^0.4.3", "typescript": "^5.0.2", - "vite": "^4.4.5" + "vite": "^4.4.5", + "vite-plugin-html-config": "^1.0.11" } } diff --git a/vite.config.ts b/vite.config.ts index 5a33944..c871b2d 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,7 +1,37 @@ -import { defineConfig } from 'vite' +import { defineConfig, loadEnv } from 'vite' import react from '@vitejs/plugin-react' +import htmlPlugin from "vite-plugin-html-config" -// https://vitejs.dev/config/ -export default defineConfig({ - plugins: [react()], -}) +const headScripts = [] + +export default defineConfig( + + ({ command, mode }) => { + + console.log(command) + const env = loadEnv(mode, process.cwd(), '') + let headScript = `console.log('analyntics will be here');` +// if (env.NODE_ENV=='production'){ + if (command=='build'){ + headScripts.push( + { + src: 'https://anl.wst74.ru/script.js', + 'data-website-id': '88168e43-88d4-4c29-bcb0-4c0cc878e7bb' + + }) + } + else headScripts.push(headScript) + + return { + // vite config + define: { + __APP_ENV__: JSON.stringify(env.APP_ENV), + }, + plugins: [ + react(), + htmlPlugin({title: 'custom title', headScripts: headScripts}) + ] + } + } + +) \ No newline at end of file