Skip to content

Commit cb83d12

Browse files
committed
build: fix vite build not including js entrypoint
1 parent 74b0d31 commit cb83d12

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

vite.config.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,19 @@ export default defineConfig(({ mode }) => {
2626
const autoInject = () => {
2727
return {
2828
name: 'html-transform',
29-
transformIndexHtml(html) {
30-
const pattern = /<!--.*VITE_AUTOINJECT.*-->/;
31-
// check if the pattern exists in the html, if not, throw error
32-
if (!pattern.test(html)) {
33-
throw new Error(`Could not find pattern ${pattern} in the html file`);
34-
}
35-
return html.replace(
36-
pattern,
37-
'<!-- Vite injected: --><script type="module" src="/src/main.js"></script>'
38-
);
29+
transformIndexHtml: {
30+
order: 'pre',
31+
handler(html) {
32+
const pattern = /<!--.*VITE_AUTOINJECT.*-->/;
33+
// check if the pattern exists in the html, if not, throw error
34+
if (!pattern.test(html)) {
35+
throw new Error(`Could not find pattern ${pattern} in the html file`);
36+
}
37+
return html.replace(
38+
pattern,
39+
'<!-- Vite injected! --><script type="module" src="/src/main.js"></script>'
40+
);
41+
},
3942
},
4043
};
4144
};

0 commit comments

Comments
 (0)