Skip to content

Commit ba1b960

Browse files
committed
Added custom script to move thi injection at bottom in the html
1 parent 372ebf2 commit ba1b960

File tree

2 files changed

+53
-16
lines changed

2 files changed

+53
-16
lines changed

index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@
150150
To begin the development, run `npm start` or `yarn start`.
151151
To create a production bundle, use `npm run build` or `yarn build`.
152152
--></body>
153+
154+
<!-- # INSERT SCRIPT HERE -->
155+
<script type="module" src="/src/index.tsx"></script>
156+
153157
<!-- Discord widget -->
154158
<script type="text/javascript">
155159
if (!window._env_.HIDE_DISCORD) {
@@ -162,5 +166,4 @@
162166
let title_el = document.querySelector('title')
163167
if (window.location.origin === 'https://preview.devtron.ai') title_el.innerHTML = 'Devtron Sandbox'
164168
</script>
165-
<script type="module" src="/src/index.tsx"></script>
166169
</html>

vite.config.ts

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,39 @@ function reactVirtualized(): PluginOption {
3333
},
3434
}
3535
}
36+
// this method is used to move all the script and styles to bottom after body
37+
const jsToBottomNoModule = () => {
38+
return {
39+
name: 'no-attribute',
40+
transformIndexHtml(html) {
41+
let customInjection = ''
42+
const scriptTag = html.match(/<script type="module"[^>]*>(.*?)<\/script[^>]*>/)[0]
43+
console.log('\n SCRIPT TAG', scriptTag, '\n')
44+
html = html.replace(scriptTag, '')
45+
customInjection += scriptTag
46+
47+
const linkTagModulePreloadList=[...html.matchAll(/<link rel="modulepreload"[^>]*>/g)]
48+
console.log('------------------------------------------------------------')
49+
linkTagModulePreloadList.forEach((linkData) => {
50+
console.log('\n modulepreload', linkData[0], '\n')
51+
html = html.replace(linkData[0], '')
52+
customInjection += linkData[0]
53+
})
54+
55+
let linkTagStyleSheetList = [...html.matchAll(/<link rel="stylesheet"[^>]*>/g)]
56+
console.log('------------------------------------------------------------')
57+
linkTagStyleSheetList.forEach((linkData) => {
58+
console.log('\n stylesheet', linkData[0], '\n')
59+
html = html.replace(linkData[0], '')
60+
customInjection += linkData[0]
61+
})
62+
63+
html = html.replace('<!-- # INSERT SCRIPT HERE -->', customInjection)
64+
console.log('------------------------------------------------------------')
65+
return html
66+
},
67+
}
68+
}
3669

3770
// https://vitejs.dev/config/
3871
export default defineConfig(({ mode }) => {
@@ -43,20 +76,20 @@ export default defineConfig(({ mode }) => {
4376
port: 3000,
4477
},
4578
build: {
46-
sourcemap: true,
47-
rollupOptions: {
48-
output: {
49-
manualChunks(id: string) {
50-
// separating the common lib chunk
51-
if (id.includes('devtron-fe-common-lib')) {
52-
return '@devtron-common';
53-
}
54-
if (id.includes('@devtron')) {
55-
return '@devtron';
56-
}
57-
},
79+
sourcemap: true,
80+
rollupOptions: {
81+
output: {
82+
manualChunks(id: string) {
83+
// separating the common lib chunk
84+
if (id.includes('devtron-fe-common-lib')) {
85+
return '@devtron-common'
86+
}
87+
if (id.includes('@devtron')) {
88+
return '@devtron'
89+
}
90+
},
91+
},
5892
},
59-
},
6093
},
6194
plugins: [
6295
// @TODO: Check if we can remove the config object inside the react plugin
@@ -78,6 +111,7 @@ export default defineConfig(({ mode }) => {
78111
filename: 'service-worker.ts',
79112
strategies: 'injectManifest',
80113
}),
114+
jsToBottomNoModule(),
81115
],
82116
// test: {
83117
// globals: true,
@@ -95,10 +129,10 @@ export default defineConfig(({ mode }) => {
95129
port: 3000,
96130
proxy: {
97131
'/orchestrator': {
98-
target: 'https://preview.devtron.ai/',
132+
target: 'https://devtron-4.devtron.info/',
99133
changeOrigin: true,
100134
},
101-
'/grafana': 'https://preview.devtron.ai/',
135+
'/grafana': 'https://devtron-4.devtron.info/',
102136
},
103137
},
104138
}

0 commit comments

Comments
 (0)