vite-plugin-rebundle 1.20.0 → 1.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ type RolldownOptions = {
8
8
  type BundleOptions = {
9
9
  [bundleName: string]: RolldownOptions;
10
10
  };
11
- declare class Rebundle {
11
+ declare class RebundleVite {
12
12
  private commonOptions;
13
13
  private bundleOptions;
14
14
  private config;
@@ -19,7 +19,7 @@ declare class Rebundle {
19
19
  private isRolldownVite;
20
20
  private ORIGINALS_DIR;
21
21
  constructor(commonOptions?: RolldownOptions | null, bundleOptions?: BundleOptions);
22
- get vite(): Plugin;
22
+ get plugin(): Plugin;
23
23
  private onConfig;
24
24
  private onConfigResolved;
25
25
  private onGenerateBundle;
@@ -33,4 +33,4 @@ declare class Rebundle {
33
33
  }
34
34
  declare function rebundle(commonOptions?: RolldownOptions | null, bundleOptions?: BundleOptions): Plugin<any>;
35
35
 
36
- export { type BundleOptions, Rebundle, type RolldownOptions, rebundle as default, rebundle };
36
+ export { type BundleOptions, RebundleVite, type RolldownOptions, rebundle as default, rebundle };
package/dist/rebundle.js CHANGED
@@ -1,13 +1,13 @@
1
1
  // src/rebundle.ts
2
- import { is } from "@eposlabs/utils";
3
2
  import chalk from "chalk";
3
+ import { is } from "dropcap/utils";
4
4
  import { filesize } from "filesize";
5
5
  import { rm, stat } from "fs/promises";
6
6
  import { extname, join } from "path";
7
7
  import { getPort } from "portfinder";
8
8
  import { rolldown } from "rolldown";
9
9
  import { WebSocketServer } from "ws";
10
- var Rebundle = class {
10
+ var RebundleVite = class {
11
11
  commonOptions;
12
12
  bundleOptions;
13
13
  config = null;
@@ -21,7 +21,7 @@ var Rebundle = class {
21
21
  this.commonOptions = commonOptions ?? {};
22
22
  this.bundleOptions = bundleOptions ?? {};
23
23
  }
24
- get vite() {
24
+ get plugin() {
25
25
  return {
26
26
  name: "vite-plugin-rebundle",
27
27
  apply: "build",
@@ -32,9 +32,6 @@ var Rebundle = class {
32
32
  writeBundle: this.onWriteBundle
33
33
  };
34
34
  }
35
- // ---------------------------------------------------------------------------
36
- // VITE HOOKS
37
- // ---------------------------------------------------------------------------
38
35
  onConfig = async (config) => {
39
36
  if (config.build?.watch) {
40
37
  this.port = await getPort({ port: 3100 });
@@ -136,11 +133,11 @@ var Rebundle = class {
136
133
  }
137
134
  };
138
135
  function rebundle(commonOptions, bundleOptions) {
139
- return new Rebundle(commonOptions, bundleOptions).vite;
136
+ return new RebundleVite(commonOptions, bundleOptions).plugin;
140
137
  }
141
138
  var rebundle_default = rebundle;
142
139
  export {
143
- Rebundle,
140
+ RebundleVite,
144
141
  rebundle_default as default,
145
142
  rebundle
146
143
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-rebundle",
3
- "version": "1.20.0",
3
+ "version": "1.22.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "imkost",
@@ -10,8 +10,8 @@
10
10
  "vite-plugin"
11
11
  ],
12
12
  "scripts": {
13
- "dev": "tsup --config ../tsup.config.ts --watch",
14
- "build": "tsup --config ../tsup.config.ts",
13
+ "dev": "tsup --config ../../tsup.config.ts --watch",
14
+ "build": "tsup --config ../../tsup.config.ts",
15
15
  "lint": "tsc --noEmit",
16
16
  "release": "sh -c 'npm version ${1:-minor} && npm run build && npm publish' --"
17
17
  },
@@ -30,14 +30,14 @@
30
30
  "dist"
31
31
  ],
32
32
  "dependencies": {
33
- "@eposlabs/utils": "^1.10.0",
34
33
  "@types/ws": "^8.18.1",
35
34
  "chalk": "^5.6.2",
35
+ "dropcap": "^1.0.0",
36
36
  "filesize": "^11.0.13",
37
37
  "portfinder": "^1.0.38",
38
- "rolldown": "^1.0.0-beta.42",
39
- "rollup": "^4.52.4",
40
- "vite": "^7.1.9",
38
+ "rolldown": "^1.0.0-beta.55",
39
+ "rollup": "^4.53.5",
40
+ "vite": "^7.3.0",
41
41
  "ws": "^8.18.3"
42
42
  }
43
43
  }
package/readme.md ADDED
@@ -0,0 +1,88 @@
1
+ # vite-plugin-rebundle
2
+
3
+ A Vite plugin that guarantees **one standalone file per entry point**. Each entry is bundled into a single file with no code-splitting or dynamic imports.
4
+
5
+ ## Why?
6
+
7
+ There are cases when you need bundles without dynamic imports. Vite doesn't provide such an option when building with multiple entries. `vite-plugin-rebundle` solves this issue by rebundling Vite’s output with [`rolldown`](https://rolldown.rs/) to enforce single-file output. This plugin runs only during `vite build`, and it does not affect the Vite dev server.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install -D vite-plugin-rebundle
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```javascript
18
+ import { defineConfig } from 'vite'
19
+ import { rebundle } from 'vite-plugin-rebundle'
20
+
21
+ export default defineConfig({
22
+ plugins: [rebundle()],
23
+ build: {
24
+ rollupOptions: {
25
+ input: {
26
+ bundle1: 'src/bundle1.js',
27
+ bundle2: 'src/bundle2.js',
28
+ },
29
+ output: {
30
+ entryFileNames: '[name].js',
31
+ },
32
+ },
33
+ },
34
+ })
35
+ ```
36
+
37
+ ## Configuration
38
+
39
+ You can provide global `rolldown` input and output options as the first argument. Per-entry options can be passed in the second argument:
40
+
41
+ ```javascript
42
+ export default defineConfig({
43
+ plugins: [
44
+ rebundle(
45
+ // Global options applied to all bundles
46
+ {
47
+ input: {...},
48
+ output: {...},
49
+ },
50
+ // Per-entry options, will be deep-merged with global options
51
+ {
52
+ bundle1: {
53
+ input: {...},
54
+ output: {...},
55
+ },
56
+ bundle2: {
57
+ input: {...},
58
+ output: {...},
59
+ },
60
+ },
61
+ ),
62
+ ],
63
+ build: {
64
+ rollupOptions: {
65
+ input: {
66
+ bundle1: 'src/bundle1.js',
67
+ bundle2: 'src/bundle2.js',
68
+ },
69
+ output: {
70
+ entryFileNames: '[name].js',
71
+ },
72
+ },
73
+ },
74
+ })
75
+ ```
76
+
77
+ ## How it works
78
+
79
+ When you run `vite build`, Vite normally outputs multiple chunks per entry if code-splitting is needed.
80
+ `vite-plugin-rebundle` hooks into the build process and **rebundles each entry’s output with rolldown**, forcing a single self-contained file per entry.
81
+
82
+ - Vite still handles the initial build (tree-shaking, asset pipeline, etc.).
83
+ - Afterward, each entry is passed through rolldown.
84
+ - The final result is one js file per entry with no dynamic imports or shared chunks.
85
+
86
+ ## Notes
87
+
88
+ Source maps are not currently supported. If you pass `sourcemap` option, it will be ignored. This plugin works with both `vite` and `rolldown-vite`.
package/src/rebundle.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { is } from '@eposlabs/utils'
2
1
  import chalk from 'chalk'
2
+ import { is } from 'dropcap/utils'
3
3
  import { filesize } from 'filesize'
4
4
  import { rm, stat } from 'node:fs/promises'
5
5
  import { extname, join } from 'node:path'
@@ -18,7 +18,7 @@ export type BundleOptions = {
18
18
  [bundleName: string]: RolldownOptions
19
19
  }
20
20
 
21
- export class Rebundle {
21
+ export class RebundleVite {
22
22
  private commonOptions: RolldownOptions
23
23
  private bundleOptions: BundleOptions
24
24
  private config: ResolvedConfig | null = null
@@ -34,7 +34,7 @@ export class Rebundle {
34
34
  this.bundleOptions = bundleOptions ?? {}
35
35
  }
36
36
 
37
- get vite(): Plugin {
37
+ get plugin(): Plugin {
38
38
  return {
39
39
  name: 'vite-plugin-rebundle',
40
40
  apply: 'build',
@@ -46,10 +46,6 @@ export class Rebundle {
46
46
  }
47
47
  }
48
48
 
49
- // ---------------------------------------------------------------------------
50
- // VITE HOOKS
51
- // ---------------------------------------------------------------------------
52
-
53
49
  private onConfig = async (config: UserConfig) => {
54
50
  if (config.build?.watch) {
55
51
  this.port = await getPort({ port: 3100 })
@@ -190,7 +186,7 @@ export class Rebundle {
190
186
  }
191
187
 
192
188
  export function rebundle(commonOptions?: RolldownOptions | null, bundleOptions?: BundleOptions) {
193
- return new Rebundle(commonOptions, bundleOptions).vite
189
+ return new RebundleVite(commonOptions, bundleOptions).plugin
194
190
  }
195
191
 
196
192
  export default rebundle