lisonge / vite-plugin-monkey

A vite plugin server and build your.user.js for userscript engine like Tampermonkey, Violentmonkey, Greasemonkey, ScriptCat
MIT License
1.31k stars 70 forks source link

Support multiple userscripts #47

Closed snordquist closed 1 year ago

snordquist commented 1 year ago
export default defineConfig(async ({ command, mode }) => ({
    plugins: [
        monkey({
            entry: 'src/entry1.ts',
            userscript: {
              // ...
            },
            build: {
                fileName: 'out1.user.js',
            },
        }),

        monkey({
            entry: 'src/entry2.ts',
            userscript: {
              // ...
            },
            build: {
                fileName: 'out2.user.js',
            },
        }),
  ]

Currently only out2.user.js is written, containing both userscript headers, which does not work with tampermonkey.

lisonge commented 1 year ago

vite has vite build and vite serve two mode, if you use vite serve , the number of entry must be one

if you just build multiple entry, you can use vite build api

// custom_build.ts
import { build } from 'vite';
import monkey from 'vite-plugin-monkey';

await build({
  configFile: false,
  plugins: [
    monkey({
      entry: 'src/entry1.ts',
      userscript: {
        namespace: 'namespace',
      },
      build: {
        fileName: 'out1.user.js',
      },
    }),
  ],
});
await build({
  configFile: false,
  plugins: [
    monkey({
      entry: 'src/entry2.ts',
      userscript: {
        namespace: 'namespace',
      },
      build: {
        fileName: 'out2.user.js',
      },
    }),
  ],
});

you can use tsx run it

pnpm exec tsx ./custom_build.ts
lisonge commented 1 year ago

if you want to manage multiple userscript/package in single git repository

you can use monorepo, pnpm monorepo is a widely used one in its implementation

the following repository all are based pnpm monorepo

such as userscripts

pnpm -F package_name serve
// startup one project serve script 

pnpm -r --filter=./packages/* serve
// startup all serve script

pnpm -F package_name build
// startup one project build

pnpm -r --filter=./packages/* build
// startup all build