vite-plugin-rebundle 1.19.0 → 1.21.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.
- package/dist/rebundle.d.ts +3 -3
- package/dist/rebundle.js +5 -9
- package/package.json +4 -4
- package/readme.md +88 -0
- package/src/rebundle.ts +4 -11
package/dist/rebundle.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ type RolldownOptions = {
|
|
|
8
8
|
type BundleOptions = {
|
|
9
9
|
[bundleName: string]: RolldownOptions;
|
|
10
10
|
};
|
|
11
|
-
declare class
|
|
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
|
|
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,
|
|
36
|
+
export { type BundleOptions, RebundleVite, type RolldownOptions, rebundle as default, rebundle };
|
package/dist/rebundle.js
CHANGED
|
@@ -7,7 +7,7 @@ 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
|
|
10
|
+
var RebundleVite = class {
|
|
11
11
|
commonOptions;
|
|
12
12
|
bundleOptions;
|
|
13
13
|
config = null;
|
|
@@ -16,12 +16,12 @@ var Rebundle = class {
|
|
|
16
16
|
ws = null;
|
|
17
17
|
isRollupVite = false;
|
|
18
18
|
isRolldownVite = false;
|
|
19
|
-
ORIGINALS_DIR = "
|
|
19
|
+
ORIGINALS_DIR = "REBUNDLE_originals";
|
|
20
20
|
constructor(commonOptions, bundleOptions) {
|
|
21
21
|
this.commonOptions = commonOptions ?? {};
|
|
22
22
|
this.bundleOptions = bundleOptions ?? {};
|
|
23
23
|
}
|
|
24
|
-
get
|
|
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 });
|
|
@@ -74,7 +71,6 @@ var Rebundle = class {
|
|
|
74
71
|
const usedPaths = [chunk.fileName, ...chunk.imports];
|
|
75
72
|
return usedPaths.some((path) => "code" in bundle[path] && bundle[path].code !== this.originals[path]);
|
|
76
73
|
});
|
|
77
|
-
if (modifiedEntryChunks.length === 0) return;
|
|
78
74
|
await Promise.all(
|
|
79
75
|
modifiedEntryChunks.map(async (chunk) => {
|
|
80
76
|
const originalFileName = this.unprefixed(chunk.fileName);
|
|
@@ -137,11 +133,11 @@ var Rebundle = class {
|
|
|
137
133
|
}
|
|
138
134
|
};
|
|
139
135
|
function rebundle(commonOptions, bundleOptions) {
|
|
140
|
-
return new
|
|
136
|
+
return new RebundleVite(commonOptions, bundleOptions).plugin;
|
|
141
137
|
}
|
|
142
138
|
var rebundle_default = rebundle;
|
|
143
139
|
export {
|
|
144
|
-
|
|
140
|
+
RebundleVite,
|
|
145
141
|
rebundle_default as default,
|
|
146
142
|
rebundle
|
|
147
143
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-rebundle",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "imkost",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"chalk": "^5.6.2",
|
|
36
36
|
"filesize": "^11.0.13",
|
|
37
37
|
"portfinder": "^1.0.38",
|
|
38
|
-
"rolldown": "^1.0.0-beta.
|
|
39
|
-
"rollup": "^4.52.
|
|
40
|
-
"vite": "^7.1.
|
|
38
|
+
"rolldown": "^1.0.0-beta.44",
|
|
39
|
+
"rollup": "^4.52.5",
|
|
40
|
+
"vite": "^7.1.12",
|
|
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
|
@@ -18,7 +18,7 @@ export type BundleOptions = {
|
|
|
18
18
|
[bundleName: string]: RolldownOptions
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export class
|
|
21
|
+
export class RebundleVite {
|
|
22
22
|
private commonOptions: RolldownOptions
|
|
23
23
|
private bundleOptions: BundleOptions
|
|
24
24
|
private config: ResolvedConfig | null = null
|
|
@@ -27,14 +27,14 @@ export class Rebundle {
|
|
|
27
27
|
private ws: WebSocketServer | null = null
|
|
28
28
|
private isRollupVite = false
|
|
29
29
|
private isRolldownVite = false
|
|
30
|
-
private ORIGINALS_DIR = '
|
|
30
|
+
private ORIGINALS_DIR = 'REBUNDLE_originals'
|
|
31
31
|
|
|
32
32
|
constructor(commonOptions?: RolldownOptions | null, bundleOptions?: BundleOptions) {
|
|
33
33
|
this.commonOptions = commonOptions ?? {}
|
|
34
34
|
this.bundleOptions = bundleOptions ?? {}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
get
|
|
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 })
|
|
@@ -104,9 +100,6 @@ export class Rebundle {
|
|
|
104
100
|
return usedPaths.some(path => 'code' in bundle[path] && bundle[path].code !== this.originals[path])
|
|
105
101
|
})
|
|
106
102
|
|
|
107
|
-
// No modified entry chunks? -> Skip rebundle
|
|
108
|
-
if (modifiedEntryChunks.length === 0) return
|
|
109
|
-
|
|
110
103
|
// Rebundle modified entry chunks
|
|
111
104
|
await Promise.all(
|
|
112
105
|
modifiedEntryChunks.map(async chunk => {
|
|
@@ -193,7 +186,7 @@ export class Rebundle {
|
|
|
193
186
|
}
|
|
194
187
|
|
|
195
188
|
export function rebundle(commonOptions?: RolldownOptions | null, bundleOptions?: BundleOptions) {
|
|
196
|
-
return new
|
|
189
|
+
return new RebundleVite(commonOptions, bundleOptions).plugin
|
|
197
190
|
}
|
|
198
191
|
|
|
199
192
|
export default rebundle
|