mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-12-11 22:06:41 +08:00
- **build: replace dotenv with vite env variables (@fehmer)** - **build: combine vite config into a single file (@fehmer)** --------- Co-authored-by: Miodec <jack@monkeytype.com>
29 lines
846 B
TypeScript
29 lines
846 B
TypeScript
import { Plugin } from "vite";
|
|
import MagicString from "magic-string";
|
|
|
|
export function jqueryInject(): Plugin {
|
|
return {
|
|
name: "simple-jquery-inject",
|
|
async transform(src: string, id: string) {
|
|
if (id.endsWith(".ts")) {
|
|
//check if file has a jQuery or $() call
|
|
if (/(?:jQuery|\$)\([^)]*\)/.test(src)) {
|
|
const s = new MagicString(src);
|
|
|
|
//if file has "use strict"; at the top, add it below that line, if not, add it at the very top
|
|
if (src.startsWith(`"use strict";`)) {
|
|
s.appendRight(12, `\nimport $ from "jquery";`);
|
|
} else {
|
|
s.prepend(`import $ from "jquery";`);
|
|
}
|
|
|
|
return {
|
|
code: s.toString(),
|
|
map: s.generateMap({ hires: true, source: id }),
|
|
};
|
|
}
|
|
}
|
|
return;
|
|
},
|
|
};
|
|
}
|