Skip to content

Commit

Permalink
Merge pull request #60 from aodn/bugs/5603-inline-newrelic
Browse files Browse the repository at this point in the history
Inline new_relic script as per docs
  • Loading branch information
utas-raymondng authored Jun 24, 2024
2 parents 0637f09 + 2503514 commit 63dd414
Show file tree
Hide file tree
Showing 5 changed files with 427 additions and 12 deletions.
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>AODN Portal</title>
<script src="public/relic_script.js"></script>
<script type="text/javascript">
<%= inlineNewRelic %>
</script>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"typescript-eslint": "^7.2.0",
"vite": "^5.0.8",
"vite-plugin-eslint": "^1.8.1",
"vite-plugin-html": "3.2.2",
"vitest": "^1.3.1"
},
"lint-staged": {
Expand Down
2 changes: 0 additions & 2 deletions public/relic_script.js

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { defineConfig, loadEnv } from "vite";
import react from "@vitejs/plugin-react-swc";
import eslint from "vite-plugin-eslint";
import path from "path";
import fs from "fs";
import { createHtmlPlugin } from "vite-plugin-html";

// https://vitejs.dev/config/
export default ({ mode }) => {
Expand Down Expand Up @@ -36,6 +38,18 @@ export default ({ mode }) => {
plugins: [
react(),
eslint({ exclude: ["/virtual:/**", "node_modules/**"] }),
// We need to inline the relic_script in the index.html, you can dynamic include based on env here
// https://docs.newrelic.com/docs/browser/new-relic-browser/page-load-timing-resources/instrumentation-browser-monitoring/#javascript-placement
createHtmlPlugin({
inject: {
data: {
inlineNewRelic: fs.readFileSync(
path.resolve(__dirname, "public/relic_script.js"),
"utf-8"
),
},
},
}),
],
build: {
outDir: "dist",
Expand Down
Loading

0 comments on commit 63dd414

Please sign in to comment.