Skip to content

Project Configuration ​

This page covers the development server and userscript configuration in vite.config.ts. Components and listeners are written in the browser entry; see Mount Components. Below is a Vue project configuration; React projects use the corresponding react() plugin:

vite.config.ts

ts
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { makoo, makooDev } from '@makoojs/cli';

export default defineConfig({
  server: { port: 5173 },
  build: { outDir: 'dist' },
  plugins: [
    vue(),
    makoo({
      entry: './src/main.ts',
      app: {
        name: 'my-script',
        version: '0.0.1',
        description: 'Tools for example.com'
      },
      monkey: {
        userscript: {
          namespace: 'npm/makoo',
          match: ['https://example.com/*']
        }
      }
    }),
    makooDev()
  ]
});

App Metadata ​

app is required. name and version generate the userscript's name and version, and description is optional.

monkey.userscript configures other metadata such as namespace, match, permissions, and resources.

Page Matching and Element Selectors ​

monkey.userscript.match decides which pages the script manager loads the script on. For example, https://example.com/* matches pages on that site. injectAt and listenAt are CSS selectors in the app code used to find elements inside the page.

After changing metadata, confirm that the installation info in the script manager has been updated; see Local Development.

Entry and Project Directory ​

entry is the app entry and can be an absolute path; relative paths are based on the root of makoo(), or on the process's current working directory when root is omitted.

Vite also has its own root. If you start the project from another directory, keep Makoo's entry resolution consistent with Vite's project root. For example, when the config file is in the project root, you can get that directory with fileURLToPath(new URL('.', import.meta.url)) and pass it to both Vite and makoo().

The browser entry and the modules it imports can use the DOM and GM APIs; don't run them in the config file that Node loads.

Development and Build Options ​

SettingWhere to write it
Server port, host, strictPortVite's server
Build directory, JS minificationVite's build
Preview port, hostVite's preview
Script file name, metadata file, external dependenciesmonkey.build of makoo()
Whether to open the install page automatically, development script namemonkey.server of makoo()
Injection status in the development terminalAdd makooDev() separately

Source maps, the assets directory, CORS, and similar settings are fixed by vite-plugin-monkey, and changing them in the Vite config has no effect; JS is not minified by default. See Settings Determined by vite-plugin-monkey.

The development script's name defaults to server: plus app.name, for example server:my-script. Pass a function to monkey.server.prefix to customize it; passing a string replaces the whole name. See Defaults and Field Constraints.

For temporary adjustments, use command-line arguments, for example pnpm exec makoo dev --port 5174; options you don't pass keep their configured values. See CLI Commands.

External Dependencies and Permissions ​

monkey.build.externalGlobals can configure dependencies as external script resources, and cdn helps generate their URLs. It only takes effect at build time; pnpm dev still uses the locally installed dependencies.

autoGrant defaults to true. At build time, the permissions required by GM APIs are inferred and written into the .user.js metadata. The development script, by contrast, always declares @grant *, so for GM APIs that work during development, still check @grant in the build output after building. For how to use GM, see Userscript API.

For the full fields, defaults, and public types, see the Vite Plugin Reference.