{"id":13496360,"url":"https://github.com/lisonge/vite-plugin-monkey","last_synced_at":"2025-05-14T00:06:00.635Z","repository":{"id":41397170,"uuid":"464839626","full_name":"lisonge/vite-plugin-monkey","owner":"lisonge","description":"A vite plugin server and build your.user.js for userscript engine like Tampermonkey, Violentmonkey, Greasemonkey, ScriptCat","archived":false,"fork":false,"pushed_at":"2025-04-27T03:03:00.000Z","size":2575,"stargazers_count":1564,"open_issues_count":8,"forks_count":84,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-05-04T07:03:00.878Z","etag":null,"topics":["greasemonkey","rollupjs","scriptcat","tampermonkey","userscript","violentmonkey","vite","vite-plugin"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lisonge.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-01T10:07:03.000Z","updated_at":"2025-05-02T11:52:02.000Z","dependencies_parsed_at":"2024-02-10T13:29:11.060Z","dependency_job_id":"9bb66b61-9dd1-4cad-b854-363fff8c9c7e","html_url":"https://github.com/lisonge/vite-plugin-monkey","commit_stats":{"total_commits":616,"total_committers":10,"mean_commits":61.6,"dds":0.02759740259740262,"last_synced_commit":"2cc0a27291023e4069b4a8e152f808b2eb6145bc"},"previous_names":[],"tags_count":156,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lisonge%2Fvite-plugin-monkey","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lisonge%2Fvite-plugin-monkey/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lisonge%2Fvite-plugin-monkey/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lisonge%2Fvite-plugin-monkey/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lisonge","download_url":"https://codeload.github.com/lisonge/vite-plugin-monkey/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254043438,"owners_count":22004955,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["greasemonkey","rollupjs","scriptcat","tampermonkey","userscript","violentmonkey","vite","vite-plugin"],"created_at":"2024-07-31T19:01:46.759Z","updated_at":"2025-05-14T00:06:00.585Z","avatar_url":"https://github.com/lisonge.png","language":"TypeScript","readme":"# vite-plugin-monkey\n\n\u003cp\u003e\n  \u003ca href=\"https://www.npmjs.com/package/vite-plugin-monkey\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/vite-plugin-monkey.svg\" alt=\"npm package\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/lisonge/vite-plugin-monkey/releases/\"\u003e\u003cimg src=\"https://img.shields.io/node/v/vite-plugin-monkey.svg\" alt=\"node compatibility\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n[README](README.md) | [中文文档](README_zh.md)\n\nA vite plugin server and build your.user.js for userscript engine like [Tampermonkey](https://www.tampermonkey.net/) and [Violentmonkey](https://violentmonkey.github.io/), [Greasemonkey](https://www.greasespot.net/), [ScriptCat](https://docs.scriptcat.org/)\n\n## Feature\n\n- support Tampermonkey, Violentmonkey, Greasemonkey, ScriptCat, etc\n- inject userscript comment to build bundle\n- auto open \\*.user.js in default browser when userscript change\n- external cdn url inject to userscript @require\n- external module inject to userscript @resource\n- use GM_api by ESM import with type hints\n- intelligently collect GM_api that is used and automatically configure userscript @grant comment\n- support `top level await` and `dynamic import` in single file\n- when vite preview, auto open browser install dist.user.js\n- full typescript support and vite feature\n\n## Quick Start\n\njust like vite create\n\n```shell\npnpm create monkey\n# npm create monkey\n# yarn create monkey\n```\n\nthen you can choose the following template\n\n| JavaScript                                                     | TypeScript                                                           |\n| -------------------------------------------------------------- | -------------------------------------------------------------------- |\n| [empty](/packages/create-monkey/template-empty) (only js)      | [empty-ts](/packages/create-monkey/template-empty-ts) (only ts)      |\n| [vanilla](/packages/create-monkey/template-vanilla) (js + css) | [vanilla-ts](/packages/create-monkey/template-vanilla-ts) (ts + css) |\n| [vue](/packages/create-monkey/template-vue)                    | [vue-ts](/packages/create-monkey/template-vue-ts)                    |\n| [react](/packages/create-monkey/template-react)                | [react-ts](/packages/create-monkey/template-react-ts)                |\n| [preact](/packages/create-monkey/template-preact)              | [preact-ts](/packages/create-monkey/template-preact-ts)              |\n| [svelte](/packages/create-monkey/template-svelte)              | [svelte-ts](/packages/create-monkey/template-svelte-ts)              |\n| [solid](/packages/create-monkey/template-solid)                | [solid-ts](/packages/create-monkey/template-solid-ts)                |\n\n\u003cdetails open\u003e\n  \u003csummary\u003eSample: Initializing a Template\u003c/summary\u003e\n\n![vue-ts](https://user-images.githubusercontent.com/38517192/191197238-214abda1-f54f-4042-a046-2d7e6cf697a2.gif)\n\n\u003c/details\u003e\n\n\u003cdetails open\u003e\n  \u003csummary\u003eSample: Hot Module Replacement\u003c/summary\u003e\n\n![hmr](https://user-images.githubusercontent.com/38517192/191197411-3d6f3795-e842-4cc1-a494-5d5f8425fd15.gif)\n\n\u003c/details\u003e\n\n\u003cdetails open\u003e\n  \u003csummary\u003eSample: Build \u0026 Preview\u003c/summary\u003e\n\n![build\u0026preview](https://user-images.githubusercontent.com/38517192/191197542-9c763af0-de2e-4a85-88c6-75a6d5924af9.gif)\n\n\u003c/details\u003e\n\n## Installation\n\n```shell\npnpm add -D vite-plugin-monkey\n# npm i -D vite-plugin-monkey\n# yarn add -D vite-plugin-monkey\n```\n\nnote: vite-plugin-monkey must be the `last item` of plugin list\n\n```mermaid\ngraph LR;\n    A(your code) -- \"others plugins/vite build\" --\u003eB(esm)\n    B -- \"vite-plugin-monkey/vite build library mode\" --\u003e C{has DynamicImport}\n    C -- yes --\u003e D(systemjs)\n    C -- no --\u003e E(iife)\n```\n\n## Config\n\n\u003c!-- template-start-MonkeyOption --\u003e\n\n[MonkeyOption](/packages/vite-plugin-monkey/src/node/types.ts#L120)\n\n\u003cdetails open\u003e\n  \u003csummary\u003eMonkeyOption Type\u003c/summary\u003e\n\n```ts\nexport type MonkeyOption = {\n  /**\n   * userscript entry file path\n   */\n  entry: string;\n  userscript?: MonkeyUserScript;\n  format?: Format;\n\n  /**\n   * alias of vite-plugin-monkey/dist/client\n   * @default '$'\n   * @example\n   * // vite-env.d.ts for type hint\n   *\n   * // if you use default value `$`\n   * /// \u003creference types=\"vite-plugin-monkey/client\" /\u003e\n   *\n   * // if you use other_alias\n   * declare module other_alias {\n   *   export * from 'vite-plugin-monkey/dist/client';\n   * }\n   */\n  clientAlias?: string;\n  server?: {\n    /**\n     * auto open install url in default browser when userscript comment change\n     *\n     * and set `viteConfig.server.open ??= monkeyConfig.server.open`\n     * @default\n     * process.platform == 'win32' || process.platform == 'darwin' // if platform is Win/Mac\n     */\n    open?: boolean;\n\n    /**\n     * name prefix, distinguish server.user.js and build.user.js in monkey extension install list, if you not want prefix, set false\n     * @default 'server:'\n     */\n    prefix?: string | ((name: string) =\u003e string) | false;\n\n    /**\n     * mount GM_api to unsafeWindow, not recommend it, you should use GM_api by ESM import, or use [unplugin-auto-import](https://github.com/antfu/unplugin-auto-import)\n     * @default false\n     * @example\n     * // if set true, you can use `vite-plugin-monkey/global` for type hint\n     * // vite-env.d.ts\n     * /// \u003creference types=\"vite-plugin-monkey/global\" /\u003e\n     */\n    mountGmApi?: boolean;\n  };\n  build?: {\n    /**\n     * build bundle userscript file name\n     *\n     * it should end with '.user.js'\n     * @default (package.json.name??'monkey')+'.user.js'\n     */\n    fileName?: string;\n\n    /**\n     * build bundle userscript comment file name, this file is only include comment\n     *\n     * it can be used by userscript.updateURL, when checking for updates, just download this small file instead of downloading the entire script\n     *\n     * it should end with '.meta.js', if set false, will not generate this file\n     *\n     * if set true, will equal to fileName.replace(/\\\\.user\\\\.js$/,'.meta.js')\n     *\n     * @default false\n     */\n    metaFileName?: string | boolean | ((fileName: string) =\u003e string);\n\n    /**\n     * this config can be array or object, array=Object.entries(object)\n     *\n     * if value is string or function, it or its return value is exportVarName\n     *\n     * if value is Array, the first [item or its return value] is exportVarName, the items after it all are url that is [require url]\n     *\n     * if module is unimported, plugin will not add require url to userscript\n     *\n     * @example\n     * { // map structure\n     *  vue:'Vue',\n     *  // if set this\n     *  // you need manually set userscript.require = ['https://unpkg.com/vue@3.0.0/dist/vue.global.js'], when `vite build`\n     *\n     *  vuex:['Vuex', (version, name)=\u003e`https://unpkg.com/${name}@${version}/dist/vuex.global.js`],\n     *  // plugin will auto add this url to userscript.require\n     *\n     *  'prettier/parser-babel': [\n     *    'prettierPlugins.babel',\n     *    (version, name, importName) =\u003e {\n     *      // name == `prettier`\n     *      // importName == `prettier/parser-babel`\n     *      const subpath = `${importName.split('/').at(-1)}.js`;\n     *      return `https://cdn.jsdelivr.net/npm/${name}@${version}/${subpath}`;\n     *    },\n     *  ],\n     *  // sometimes importName deffers from package name\n     * }\n     * @example\n     * [ // array structure, this example come from [playground/ex-vue-demi](https://github.com/lisonge/vite-plugin-monkey/tree/main/playground/ex-vue-demi)\n     *   [\n     *     'vue',\n     *     cdn\n     *       .jsdelivr('Vue', 'dist/vue.global.prod.js')\n     *       .concat('https://unpkg.com/vue-demi@latest/lib/index.iife.js')\n     *       .concat(\n     *         await util.fn2dataUrl(() =\u003e {\n     *           window.Vue = Vue;\n     *         }),\n     *       ),\n     *   ],\n     *   ['pinia', cdn.jsdelivr('Pinia', 'dist/pinia.iife.prod.js')],\n     *   [\n     *     'element-plus',\n     *     cdn.jsdelivr('ElementPlus', 'dist/index.full.min.js'),\n     *   ],\n     * ]\n     */\n    externalGlobals?: ExternalGlobals;\n\n    /**\n     * according to final code bundle, auto inject GM_* or GM.* to userscript comment grant\n     *\n     * tree shaking code, then if code.includes('GM_xxx'), add \\@grant GM_xxx to userscript\n     * @default true\n     */\n    autoGrant?: boolean;\n\n    /**\n     * @deprecated use [viteConfig.build.cssMinify](https://vitejs.dev/config/build-options.html#build-cssminify) in vite\u003e=4.2.0\n     *\n     * now minifyCss will not work\n     */\n    minifyCss?: boolean;\n\n    /**\n     * @example\n     * {  // resourceName default value is pkg.importName\n     *   'element-plus/dist/index.css': pkg=\u003e`https://unpkg.com/${pkg.name}@${pkg.version}/${pkg.resolveName}`,\n     *   'element-plus/dist/index.css': {\n     *     resourceName: pkg=\u003epkg.importName,\n     *     resourceUrl: pkg=\u003e`https://unpkg.com/${pkg.name}@${pkg.version}/${pkg.resolveName}`,\n     *     loader: pkg=\u003e{ // there are default loaders that support [css, json, the assets that vite support, ?url, ?raw] file/name suffix\n     *        const css = GM_getResourceText(pkg.resourceName);\n     *        GM_addStyle(css);\n     *        return css;\n     *     },\n     *     nodeLoader: pkg=\u003e{\n     *        return [\n     *          `export default (()=\u003e{`,\n     *          `const css = GM_getResourceText(${JSON.stringify(pkg.resourceName)});`,\n     *          `GM_addStyle(css);`,\n     *          `return css;`,\n     *          `})();`\n     *        ].join('');\n     *     },\n     *   },\n     *   'element-plus/dist/index.css': [\n     *      (version, name, importName, resolveName)=\u003eimportName,\n     *      (version, name, importName, resolveName)=\u003e`https://unpkg.com/${name}@${version}/${resolveName}`,\n     *       // for compat externalGlobals cdn function, if (version/name/importName/resolveName) == '', plugin will use their own default values\n     *   ],\n     *   'element-plus/dist/index.css': cdn.jsdelivr(),\n     * }\n     */\n    externalResource?: ExternalResource;\n\n    /**\n     * when use dynamic-import, plugin will use systemjs build your code\n     *\n     * `cdn.jsdelivr()[1]` example -\u003e [dynamic-import.user.js](https://github.com/lisonge/vite-plugin-monkey/blob/7645b185605faf9b48c43116db5ea01726188e03/playground/dynamic-import/dist/dynamic-import.user.js)\n     *\n     * `'inline'` exmple -\u003e [test-v3.user.js](https://github.com/lisonge/vite-plugin-monkey/blob/7645b185605faf9b48c43116db5ea01726188e03/playground/test-v3/dist/test-v3.user.js)\n     *\n     * @default\n     * cdn.jsdelivr()[1]\n     */\n    systemjs?: 'inline' | ModuleToUrlFc;\n\n    /**\n     * @default\n     * const defaultFc = () =\u003e {\n     *   return (e: string) =\u003e {\n     *     if (typeof GM_addStyle == 'function') {\n     *       GM_addStyle(e);\n     *       return;\n     *     }\n     *     const o = document.createElement('style');\n     *     o.textContent = e;\n     *     document.head.append(o);\n     *   };\n     * };\n     * @example\n     * const defaultFc1 = () =\u003e {\n     *   return (e: string) =\u003e {\n     *     const o = document.createElement('style');\n     *     o.textContent = e;\n     *     document.head.append(o);\n     *   };\n     * };\n     * const defaultFc2 = (css:string)=\u003e{\n     *   const t = JSON.stringify(css)\n     *   return `(e=\u003e{const o=document.createElement(\"style\");o.textContent=e,document.head.append(o)})(${t})`\n     * }\n     */\n    cssSideEffects?: (\n      css: string,\n    ) =\u003e IPromise\u003cstring | ((css: string) =\u003e void)\u003e;\n  };\n};\n```\n\n\u003c/details\u003e\n\n\u003c!-- template-end-MonkeyOption --\u003e\n\n## CDN util for external\n\n```ts\nimport { defineConfig } from 'vite';\nimport monkey, { cdn } from 'vite-plugin-monkey';\nexport default defineConfig({\n  plugins: [\n    monkey({\n      build: {\n        externalGlobals: {\n          react: cdn.jsdelivr('React', 'umd/react.production.min.js'),\n        },\n        externalResource: {\n          'element-plus/dist/index.css': cdn.jsdelivr(),\n        },\n      },\n    }),\n  ],\n});\n```\n\nthere is the following cdn to use, full detail see [cdn.ts](/packages/vite-plugin-monkey/src/node/cdn.ts)\n\n- [jsdelivr](https://www.jsdelivr.com/)\n- [unpkg](https://unpkg.com/)\n- [bytecdntp](https://cdn.bytedance.com/)\n- [baomitu](https://cdn.baomitu.com/)\n- [cdnjs](https://cdnjs.com/libraries)\n- [zhimg](https://unpkg.zhimg.com/)\n- [npmmirror](https://registry.npmmirror.com/)\n\nif you want use other cdn, you can see [external-scripts](https://greasyfork.org/help/external-scripts)\n\n## Minify\n\nbecause of the [code-rules](https://greasyfork.org/en/help/code-rules) of greasyfork\n\n\u003e Code posted to Greasy Fork must not be obfuscated or minified\n\nso plugin will change the default value of [viteConfig.build.minify](https://cn.vitejs.dev/config/build-options.html#build-minify) to `false`\n\nif you want to enable minify, just set `viteConfig.build.minify=true`\n\n## GM_api usage\n\n### ESM usage\n\nwe can use GM_api by esm module\n\n```ts\n// main.ts\nimport { GM_cookie, unsafeWindow, monkeyWindow, GM_addElement } from '$';\n// $ is the default alias of vite-plugin-monkey/dist/client\n// if you want use 'others', set monkeyConfig.clientAlias='others'\n\n// whatever it is serve or build mode, monkeyWindow is always the window of [UserScript Scope]\nconsole.log(monkeyWindow);\n\nGM_addElement(document.body, 'div', { innerHTML: 'hello' });\n\n// whatever it is serve or build mode, unsafeWindow is always host window\nif (unsafeWindow == window) {\n  console.log('scope-\u003ehost, host esm scope');\n} else {\n  console.log('scope-\u003emonkey, userscript scope');\n}\n\nGM_cookie.list({}, (cookies, error) =\u003e {\n  if (error) {\n    console.log(error);\n  } else {\n    const [cookie] = cookies;\n    if (cookie) {\n      console.log(cookie);\n    }\n  }\n});\n```\n\n### Global variables usage\n\nset `monkeyConfig.server.mountGmApi=true`\n\n```ts\n// vite.config.ts\nimport { defineConfig } from 'vite';\nimport monkey from 'vite-plugin-monkey';\n\nexport default defineConfig({\n  plugins: [\n    monkey({\n      // ...\n      server: { mountGmApi: true },\n    }),\n  ],\n});\n```\n\nGM_api will mount to the property of `host window/globalThis`\n\n```ts\n// main.ts\nconsole.log(GM_cookie == globalThis.GM_cookie);\nconsole.log({ GM_cookie, unsafeWindow, monkeyWindow, GM_addElement });\n```\n\n### Auto import usage\n\nuse [unplugin-auto-import](https://github.com/antfu/unplugin-auto-import)\n\n```ts\n// vite.config.ts\nimport { defineConfig } from 'vite';\nimport monkey, { util } from 'vite-plugin-monkey';\nimport AutoImport from 'unplugin-auto-import/vite';\n\nexport default defineConfig({\n  plugins: [\n    AutoImport({\n      imports: [util.unimportPreset],\n    }),\n    monkey({\n      // ...\n    }),\n  ],\n});\n```\n\n```ts\n// main.ts\n// auto import example\nconsole.log({ GM_cookie, unsafeWindow, monkeyWindow, GM_addElement });\n```\n\n## Example\n\ntest examples, see [/playground](/playground)\n\nand preact/react/svelte/vanilla/vue/solid examples, see [create-monkey](/packages/create-monkey)\n\n## Some note\n\n### Work with other plugins\n\nplugin will rebuild your code by [generateBundle](https://rollupjs.org/plugin-development/#generatebundle) hook\n\nplease ensure that the order of the plugin is **the last one**\n\n### [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP)\n\nin `vite serve` mode, the code entry is added as script to target host document.head, code need work between two origins\n\nbut the browser will prevent the execution of this script according to the CSP strategy\n\nnow just use browser extension [Disable-CSP](https://github.com/lisonge/Disable-CSP)\n\n### Mixed IIFE and UMD at @require\n\nthe variable declared by `var` from iife-cdn will not become the property of window at monkeyWindow scope, because monkeyWindow scope is not global scope\n\nso if an umd lib is dependent on an iife lib, such as `element-plus` is dependent on `vue`, `element-plus` cdn will not work\n\ndetail see [issues/5](https://github.com/lisonge/vite-plugin-monkey/issues/5) or [greasyfork#1084](https://github.com/JasonBarnabe/greasyfork/issues/1084)\n\nthe solution is that we append a dataUrl script that will set iife-variable as the property of window after iife-cdn\n\n```ts\nimport { defineConfig } from 'vite';\nimport monkey, { cdn, util } from 'vite-plugin-monkey';\n\nexport default defineConfig(async ({ command, mode }) =\u003e ({\n  plugins: [\n    monkey({\n      // ...\n      build: {\n        externalGlobals: {\n          vue: cdn\n            .jsdelivr('Vue', 'dist/vue.global.prod.js')\n            .concat(util.dataUrl(';window.Vue=Vue;')),\n          'element-plus': cdn.jsdelivr('ElementPlus', 'dist/index.full.min.js'),\n        },\n      },\n    }),\n  ],\n}));\n```\n\n### Polyfill\n\nwhen plugin works with vite legacy, it is necessary to set `renderLegacyChunks=false`\n\n```ts\n// vite.config.ts\nimport legacy from '@vitejs/plugin-legacy';\nimport { defineConfig } from 'vite';\nimport monkey from 'vite-plugin-monkey';\n\nexport default defineConfig({\n  plugins: [\n    legacy({\n      renderLegacyChunks: false,\n      modernPolyfills: true,\n    }),\n    monkey({\n      entry: './src/main.ts',\n    }),\n  ],\n});\n```\n\n## How to Properly Build a Library Using GM_api\n\nIf you want to encapsulate GM_api to build a library for others to use\n\nThe previous practice generally involved accessing GM_api as a global variable directly in the library code and then referencing and loading it in userscript through `@require`.\n\nHowever, this approach does not allow us to manage this dependency through npm or other package managers, and it is not compatible with the usage of ESM GM_api in vite-plugin-monkey.\n\nNow, you only need to import GM_api normally from `vite-plugin-monkey/dist/client` in your library code. Modify your build config and exclude `vite-plugin-monkey/dist/client`.\n\nThis way, you can build a library that can be used in vite-plugin-monkey. Users of this library only need to install it via npm and use it normally with `import`.\n\nOf course, if you directly bundle `vite-plugin-monkey/dist/client` into the build artifact, the library can also be referenced directly through `@require`.\n\nHowever, to make the build artifact more concise, it is recommended that you redirect `vite-plugin-monkey/dist/client` to `vite-plugin-monkey/dist/native` during the build.\n\nBelow is an example using tsup to simultaneously package ESM and IIFE formats. ESM is provided to vite-plugin-monkey users, and IIFE is provided to users who want to reference it through `@require`.\n\nAdditionally, the IIFE format can also be used as a configuration for vite-plugin-monkey's externalGlobals to reduce the size of the build artifact.\n\n```ts\n// /src/index.ts\nimport { GM_setValue } from 'vite-plugin-monkey/dist/client';\n\nexport const setValue = (name: string, value: unknown) =\u003e {\n  console.log('you invoke setValue', name, value);\n  GM_setValue(name, value);\n};\n```\n\n```ts\n// tsup.config.ts\nimport { defineConfig } from 'tsup';\n\nconst outExtension = (ctx: { format: 'esm' | 'cjs' | 'iife' }) =\u003e ({\n  js: { esm: '.mjs', cjs: '.cjs', iife: '.iife.js' }[ctx.format],\n});\n\nexport default defineConfig([\n  {\n    // for vite import\n    entry: ['src/index.ts'],\n    outDir: 'dist',\n    sourcemap: true,\n    platform: 'browser',\n    outExtension,\n    dts: true,\n    format: ['esm'],\n    external: ['vite-plugin-monkey/dist/client'],\n  },\n  {\n    // for userscript @require\n    entry: ['src/index.ts'],\n    outDir: 'dist',\n    sourcemap: true,\n    platform: 'browser',\n    outExtension,\n    dts: false,\n    format: ['iife'],\n    minify: true,\n    globalName: `GmExtra`,\n    target: 'es2015',\n    esbuildOptions: (options) =\u003e {\n      options.alias = {\n        'vite-plugin-monkey/dist/client': 'vite-plugin-monkey/dist/native',\n      };\n    },\n  },\n]);\n```\n\n## Contribution\n\nplease commit your changes to [dev](https://github.com/lisonge/vite-plugin-monkey/tree/dev) branch\n","funding_links":[],"categories":["TypeScript","Tutorials"],"sub_categories":["\u003cpicture\u003e\u003csource type=\"image/png\" media=\"(prefers-color-scheme: dark)\" srcset=\"https://cdn.jsdelivr.net/gh/awesome-scripts/awesome-userscripts@f11c95f/assets/images/icons/sites/youtube/white/icon32.png\"\u003e\u003cimg height=17 src=\"https://cdn.jsdelivr.net/gh/awesome-scripts/awesome-userscripts@f11c95f/assets/images/icons/sites/youtube/icon32.png\"\u003e\u003c/picture\u003e YouTube"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flisonge%2Fvite-plugin-monkey","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flisonge%2Fvite-plugin-monkey","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flisonge%2Fvite-plugin-monkey/lists"}