vite-plugin-rebundle 1.2.3 → 1.2.6
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.js +16 -6
- package/package.json +4 -1
- package/readme.md +1 -3
package/dist/rebundle.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { filesize } from 'filesize';
|
|
1
2
|
import * as $esbuild from 'esbuild';
|
|
2
3
|
import * as $fs from 'node:fs/promises';
|
|
3
4
|
import * as $path from 'node:path';
|
|
@@ -42,7 +43,7 @@ export class Rebundle extends $utils.Unit {
|
|
|
42
43
|
onConfigResolved = async (config) => {
|
|
43
44
|
// Save resolved config
|
|
44
45
|
this.config = config;
|
|
45
|
-
// Hide .js files from output logs
|
|
46
|
+
// Hide .js files from output logs (rollup only, not supported in rolldown)
|
|
46
47
|
const info = this.config.logger.info;
|
|
47
48
|
this.config.logger.info = (message, options) => {
|
|
48
49
|
const path = message.split(/\s+/)[0];
|
|
@@ -68,6 +69,9 @@ export class Rebundle extends $utils.Unit {
|
|
|
68
69
|
await Promise.all(entryJsChunks.map(async (chunk) => {
|
|
69
70
|
if (!this.config)
|
|
70
71
|
throw this.never;
|
|
72
|
+
// Delete chunk from bundle to hide log in vite-rolldown.
|
|
73
|
+
// Call for rollup as well for consistency.
|
|
74
|
+
delete bundle[chunk.fileName];
|
|
71
75
|
const chunkPath = this.outPath(chunk.fileName);
|
|
72
76
|
const chunkBuildOptions = options[chunk.name] ?? {};
|
|
73
77
|
const chunkFiles = await this.readChunkFiles(chunk);
|
|
@@ -90,10 +94,12 @@ export class Rebundle extends $utils.Unit {
|
|
|
90
94
|
if (result.errors.length > 0)
|
|
91
95
|
return;
|
|
92
96
|
// Log successful build
|
|
97
|
+
const { size } = await $fs.stat(chunkPath);
|
|
93
98
|
const _outDir_ = $chalk.dim(`${this.outDir}/`);
|
|
94
99
|
const _fileName_ = $chalk.cyan(chunk.fileName);
|
|
95
|
-
const _rebundle_ = $chalk.dim.cyan('rebundle');
|
|
96
|
-
|
|
100
|
+
const _rebundle_ = $chalk.dim.cyan('[rebundle]');
|
|
101
|
+
const _size_ = $chalk.bold.dim(`${filesize(size)}`);
|
|
102
|
+
console.log(`${_outDir_}${_fileName_} ${_rebundle_} ${_size_}`);
|
|
97
103
|
// Mark chunk as changed
|
|
98
104
|
changedChunkNames.push(chunk.name);
|
|
99
105
|
// Save chunk content
|
|
@@ -122,11 +128,11 @@ export class Rebundle extends $utils.Unit {
|
|
|
122
128
|
// Remove all non-entry chunks
|
|
123
129
|
for (const chunk of nonEntryChunks) {
|
|
124
130
|
// Remove chunk
|
|
125
|
-
await $fs.unlink(this.outPath(chunk.fileName));
|
|
131
|
+
await $utils.safe($fs.unlink(this.outPath(chunk.fileName)));
|
|
126
132
|
delete bundle[chunk.fileName];
|
|
127
133
|
// Remove sourcemap
|
|
128
134
|
if (chunk.sourcemapFileName) {
|
|
129
|
-
await $fs.unlink(this.outPath(chunk.sourcemapFileName));
|
|
135
|
+
await $utils.safe($fs.unlink(this.outPath(chunk.sourcemapFileName)));
|
|
130
136
|
delete bundle[chunk.sourcemapFileName];
|
|
131
137
|
}
|
|
132
138
|
// Remove containing directory if empty (recursively)
|
|
@@ -134,7 +140,7 @@ export class Rebundle extends $utils.Unit {
|
|
|
134
140
|
await this.removeDirectoryIfEmpty(dir);
|
|
135
141
|
}
|
|
136
142
|
// Notify about changed chunks
|
|
137
|
-
if (changedChunkNames.length > 0) {
|
|
143
|
+
if (ws && changedChunkNames.length > 0) {
|
|
138
144
|
ws.clients.forEach(client => client.send(JSON.stringify(changedChunkNames)));
|
|
139
145
|
}
|
|
140
146
|
};
|
|
@@ -160,6 +166,10 @@ export class Rebundle extends $utils.Unit {
|
|
|
160
166
|
return this.ws;
|
|
161
167
|
if (!this.port)
|
|
162
168
|
throw this.never;
|
|
169
|
+
if (!this.config)
|
|
170
|
+
throw this.never;
|
|
171
|
+
if (!this.config.build.watch)
|
|
172
|
+
return null;
|
|
163
173
|
this.ws = new $ws.WebSocketServer({ port: this.port });
|
|
164
174
|
return this.ws;
|
|
165
175
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-rebundle",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "imkost",
|
|
@@ -28,7 +28,10 @@
|
|
|
28
28
|
"@types/ws": "^8.18.1",
|
|
29
29
|
"chalk": "^5.6.0",
|
|
30
30
|
"esbuild": "^0.25.9",
|
|
31
|
+
"filesize": "^11.0.2",
|
|
31
32
|
"portfinder": "^1.0.37",
|
|
33
|
+
"rollup": "^4.50.0",
|
|
34
|
+
"vite": "^7.1.4",
|
|
32
35
|
"ws": "^8.18.3"
|
|
33
36
|
}
|
|
34
37
|
}
|
package/readme.md
CHANGED
|
@@ -6,8 +6,6 @@ A Vite plugin that guarantees **one standalone file per entry point**. Each entr
|
|
|
6
6
|
|
|
7
7
|
Sometimes you need bundles without dynamic imports. Vite/Rollup don’t provide this option when building with multiple entries. This plugin solves it by rebundling Vite’s output with esbuild to enforce single-file output.
|
|
8
8
|
|
|
9
|
-
> ℹ️ Useful when targeting environments that require standalone files (e.g., browser extensions, legacy systems, or file-based distribution).
|
|
10
|
-
|
|
11
9
|
> ⚠️ This plugin runs **only during** `vite build`. It does not affect the Vite dev server.
|
|
12
10
|
|
|
13
11
|
## Installation
|
|
@@ -38,7 +36,7 @@ export default defineConfig({
|
|
|
38
36
|
})
|
|
39
37
|
```
|
|
40
38
|
|
|
41
|
-
|
|
39
|
+
## Options
|
|
42
40
|
|
|
43
41
|
You can provide **esbuild options per entry point**. This is useful, for example, to inject custom define variables into specific bundles:
|
|
44
42
|
|