Skip to content

Commit

Permalink
feat: change entry
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Jul 13, 2022
1 parent 7e7f826 commit 2ee31fb
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/inject_template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ export const template2string = <T extends (args: any) => any>(
return `;(${func.toString()})(${JSON.stringify(arg, undefined, 2)});`;
};

export const serverInjectTemplate = ({
origin = 'http://127.0.0.1:3000',
entry = 'src/main.ts',
}) => {
export const serverInjectTemplate = ({ entryList = [] as string[] }) => {
if (window.unsafeWindow) {
const injectWindow = window.unsafeWindow;
let sum = 0;
Expand Down Expand Up @@ -77,7 +74,7 @@ export const serverInjectTemplate = ({
return el;
};
const { head } = document;
[`${origin}/@vite/client`, `${origin}/${entry}`].reverse().forEach((s) => {
entryList.reverse().forEach((s) => {
head.insertBefore(createScript(s), head.firstChild);
});
console.log('[vite-plugin-monkey] inject module to document.head');
Expand All @@ -91,3 +88,12 @@ export const cssInjectTemplate = ({ cssTextList = [] as string[] }) => {
document.head.appendChild(style);
});
};

export const redirectFn = ({ url = '' }) => {
setTimeout(async () => {
window.location.href = url;
setTimeout(() => {
window.close();
}, 500);
});
};

0 comments on commit 2ee31fb

Please sign in to comment.