vite-plugin-rebundle 2.0.2 → 2.0.3
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 +2 -4
- package/dist/rebundle.js +22 -32
- package/dist/rebundle.js.map +1 -1
- package/package.json +2 -1
- /package/{README.md → readme.md} +0 -0
package/dist/rebundle.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { InputOptions, OutputOptions } from 'rolldown';
|
|
2
2
|
import type { Plugin } from 'vite';
|
|
3
3
|
declare global {
|
|
4
4
|
interface ImportMetaEnv {
|
|
@@ -19,9 +19,7 @@ export declare class Rebundle {
|
|
|
19
19
|
private originals;
|
|
20
20
|
private port;
|
|
21
21
|
private ws;
|
|
22
|
-
private
|
|
23
|
-
private isRolldownVite;
|
|
24
|
-
private ORIGINALS_DIR;
|
|
22
|
+
private ORIGINALS;
|
|
25
23
|
constructor(commonOptions?: RolldownOptions | null, bundleOptions?: BundleOptions);
|
|
26
24
|
get plugin(): Plugin;
|
|
27
25
|
private onConfig;
|
package/dist/rebundle.js
CHANGED
|
@@ -2,7 +2,7 @@ import { is } from '@eposlabs/utils';
|
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import { filesize } from 'filesize';
|
|
4
4
|
import { rm, stat } from 'node:fs/promises';
|
|
5
|
-
import {
|
|
5
|
+
import { join } from 'node:path';
|
|
6
6
|
import { getPort } from 'portfinder';
|
|
7
7
|
import { rolldown } from 'rolldown';
|
|
8
8
|
import { WebSocketServer } from 'ws';
|
|
@@ -13,9 +13,7 @@ export class Rebundle {
|
|
|
13
13
|
originals = {};
|
|
14
14
|
port = null;
|
|
15
15
|
ws = null;
|
|
16
|
-
|
|
17
|
-
isRolldownVite = false;
|
|
18
|
-
ORIGINALS_DIR = 'ORIGINALS';
|
|
16
|
+
ORIGINALS = 'ORIGINALS'; // Temporary folder for original chunks
|
|
19
17
|
constructor(commonOptions, bundleOptions) {
|
|
20
18
|
this.commonOptions = commonOptions ?? {};
|
|
21
19
|
this.bundleOptions = bundleOptions ?? {};
|
|
@@ -34,33 +32,31 @@ export class Rebundle {
|
|
|
34
32
|
// MARK: Vite Hooks
|
|
35
33
|
// ============================================================================
|
|
36
34
|
onConfig = async (config) => {
|
|
35
|
+
const onLog = config.build?.rolldownOptions?.onLog ?? null;
|
|
37
36
|
if (config.build?.watch) {
|
|
38
37
|
this.port = await getPort({ port: 3100 });
|
|
39
38
|
this.ws = new WebSocketServer({ port: this.port });
|
|
40
39
|
}
|
|
41
40
|
return {
|
|
42
|
-
define: {
|
|
43
|
-
|
|
41
|
+
define: {
|
|
42
|
+
'import.meta.env.REBUNDLE_PORT': JSON.stringify(this.port),
|
|
43
|
+
},
|
|
44
|
+
build: {
|
|
45
|
+
sourcemap: false,
|
|
46
|
+
rolldownOptions: {
|
|
47
|
+
onLog: (level, log, defaultLogger) => {
|
|
48
|
+
if (log.code === 'FILE_NAME_CONFLICT')
|
|
49
|
+
return;
|
|
50
|
+
if (onLog)
|
|
51
|
+
return onLog(level, log, defaultLogger);
|
|
52
|
+
return defaultLogger(level, log);
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
44
56
|
};
|
|
45
57
|
};
|
|
46
58
|
onConfigResolved = async (config) => {
|
|
47
|
-
// Detect Vite variant
|
|
48
|
-
this.isRollupVite = !('oxc' in config);
|
|
49
|
-
this.isRolldownVite = !this.isRollupVite;
|
|
50
|
-
// Save resolved config
|
|
51
59
|
this.config = config;
|
|
52
|
-
// Hide js files from output logs for rollup Vite
|
|
53
|
-
if (this.isRollupVite) {
|
|
54
|
-
const info = this.config.logger.info;
|
|
55
|
-
this.config.logger.info = (message, options) => {
|
|
56
|
-
const path = message.split(/\s+/)[0];
|
|
57
|
-
if (is.absent(path))
|
|
58
|
-
return;
|
|
59
|
-
if (extname(path) === '.js')
|
|
60
|
-
return;
|
|
61
|
-
info(message, options);
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
60
|
};
|
|
65
61
|
onGenerateBundle = (_, bundle) => {
|
|
66
62
|
for (const chunk of this.getChunks(bundle)) {
|
|
@@ -68,11 +64,6 @@ export class Rebundle {
|
|
|
68
64
|
// Move all chunks to a temporary subfolder
|
|
69
65
|
chunk.fileName = this.prefixed(originalFileName);
|
|
70
66
|
chunk.imports = chunk.imports.map(name => this.prefixed(name));
|
|
71
|
-
// Use prefixed names as bundle keys for rollup Vite (rolldown Vite does this automatically)
|
|
72
|
-
if (this.isRollupVite) {
|
|
73
|
-
bundle[chunk.fileName] = chunk;
|
|
74
|
-
delete bundle[originalFileName];
|
|
75
|
-
}
|
|
76
67
|
}
|
|
77
68
|
};
|
|
78
69
|
onWriteBundle = async (_, bundle) => {
|
|
@@ -112,11 +103,10 @@ export class Rebundle {
|
|
|
112
103
|
// Save original chunk code
|
|
113
104
|
this.originals[chunk.fileName] = chunk.code;
|
|
114
105
|
// Delete chunk from the bundle to hide Vite's output log
|
|
115
|
-
|
|
116
|
-
delete bundle[chunk.fileName];
|
|
106
|
+
delete bundle[chunk.fileName];
|
|
117
107
|
}
|
|
118
108
|
// Remove folder with original chunks
|
|
119
|
-
await rm(join(this.dist, this.
|
|
109
|
+
await rm(join(this.dist, this.ORIGINALS), { recursive: true });
|
|
120
110
|
// Notify about modified chunks
|
|
121
111
|
if (this.ws && modifiedEntryChunks.length > 0) {
|
|
122
112
|
const names = modifiedEntryChunks.map(chunk => chunk.name);
|
|
@@ -131,10 +121,10 @@ export class Rebundle {
|
|
|
131
121
|
return this.config.build.outDir;
|
|
132
122
|
}
|
|
133
123
|
prefixed(path) {
|
|
134
|
-
return join(this.
|
|
124
|
+
return join(this.ORIGINALS, path);
|
|
135
125
|
}
|
|
136
126
|
unprefixed(path) {
|
|
137
|
-
return path.replace(`${this.
|
|
127
|
+
return path.replace(`${this.ORIGINALS}/`, '');
|
|
138
128
|
}
|
|
139
129
|
getChunks(bundle) {
|
|
140
130
|
return Object.values(bundle).filter(item => item.type === 'chunk');
|
package/dist/rebundle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rebundle.js","sourceRoot":"","sources":["../src/rebundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAA;AACpC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACnC,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"rebundle.js","sourceRoot":"","sources":["../src/rebundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAA;AACpC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACnC,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpC,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEnC,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAA;AAiBpC,MAAM,OAAO,QAAQ;IACX,aAAa,CAAiB;IAC9B,aAAa,CAAe;IAC5B,MAAM,GAA0B,IAAI,CAAA;IACpC,SAAS,GAA2B,EAAE,CAAA;IACtC,IAAI,GAAkB,IAAI,CAAA;IAC1B,EAAE,GAA2B,IAAI,CAAA;IACjC,SAAS,GAAG,WAAW,CAAA,CAAC,uCAAuC;IAEvE,YAAY,aAAsC,EAAE,aAA6B;QAC/E,IAAI,CAAC,aAAa,GAAG,aAAa,IAAI,EAAE,CAAA;QACxC,IAAI,CAAC,aAAa,GAAG,aAAa,IAAI,EAAE,CAAA;IAC1C,CAAC;IA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eAAe,QAAQ,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-rebundle",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "imkost",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"vite",
|
|
10
10
|
"vite-plugin"
|
|
11
11
|
],
|
|
12
|
+
"homepage": "https://github.com/eposlabs/epos/tree/main/packages/vite-plugin-rebundle",
|
|
12
13
|
"repository": {
|
|
13
14
|
"type": "git",
|
|
14
15
|
"url": "git+https://github.com/eposlabs/epos.git",
|
/package/{README.md → readme.md}
RENAMED
|
File without changes
|