vite-plugin-rebundle 1.0.0 → 1.1.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 +2 -7
- package/dist/rebundle.js +4 -30
- package/package.json +2 -3
package/dist/rebundle.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { BuildOptions } from 'esbuild';
|
|
2
2
|
import type { Plugin } from 'vite';
|
|
3
|
-
export type Options =
|
|
4
|
-
|
|
5
|
-
[chunkName: string]: BuildOptions;
|
|
6
|
-
};
|
|
3
|
+
export type Options = {
|
|
4
|
+
[chunkName: string]: BuildOptions;
|
|
7
5
|
};
|
|
8
6
|
export type ContentMap = {
|
|
9
7
|
[path: string]: string;
|
|
@@ -11,15 +9,12 @@ export type ContentMap = {
|
|
|
11
9
|
export declare class Rebundle {
|
|
12
10
|
private options;
|
|
13
11
|
private config;
|
|
14
|
-
private emptyOutDir;
|
|
15
12
|
private content;
|
|
16
13
|
constructor(options: Options);
|
|
17
14
|
get plugin(): Plugin;
|
|
18
|
-
private onConfig;
|
|
19
15
|
private onConfigResolved;
|
|
20
16
|
private onWriteBundle;
|
|
21
17
|
private get outDir();
|
|
22
18
|
private getChunkContentMap;
|
|
23
|
-
private without;
|
|
24
19
|
private get never();
|
|
25
20
|
}
|
package/dist/rebundle.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import $chalk from 'chalk';
|
|
2
2
|
import * as $esbuild from 'esbuild';
|
|
3
|
-
import * as $merge from 'merge-anything';
|
|
4
3
|
import * as $fs from 'node:fs/promises';
|
|
5
4
|
import * as $path from 'node:path';
|
|
6
5
|
export class Rebundle {
|
|
7
6
|
options;
|
|
8
7
|
config = null;
|
|
9
|
-
emptyOutDir = true;
|
|
10
8
|
content = {};
|
|
11
9
|
constructor(options) {
|
|
12
10
|
this.options = options;
|
|
@@ -16,7 +14,6 @@ export class Rebundle {
|
|
|
16
14
|
name: 'vite-plugin-rebundle',
|
|
17
15
|
apply: 'build',
|
|
18
16
|
enforce: 'post',
|
|
19
|
-
config: this.onConfig,
|
|
20
17
|
configResolved: this.onConfigResolved,
|
|
21
18
|
writeBundle: this.onWriteBundle,
|
|
22
19
|
};
|
|
@@ -24,23 +21,9 @@ export class Rebundle {
|
|
|
24
21
|
// ---------------------------------------------------------------------------
|
|
25
22
|
// HOOKS
|
|
26
23
|
// ---------------------------------------------------------------------------
|
|
27
|
-
onConfig = (config) => {
|
|
28
|
-
// Save user's `emptyOutDir` value
|
|
29
|
-
this.emptyOutDir = config.build?.emptyOutDir ?? true;
|
|
30
|
-
// Make `emptyOutDir = false` to prevent Vite from deleting rebundled output files
|
|
31
|
-
return {
|
|
32
|
-
build: {
|
|
33
|
-
emptyOutDir: false,
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
24
|
onConfigResolved = async (config) => {
|
|
38
25
|
// Save resolved config
|
|
39
26
|
this.config = config;
|
|
40
|
-
// Cleanup output directory if user's `emptyOutDir` is `true`
|
|
41
|
-
if (this.emptyOutDir) {
|
|
42
|
-
await $fs.rmdir(this.outDir, { recursive: true });
|
|
43
|
-
}
|
|
44
27
|
// Hide .js files from output logs
|
|
45
28
|
const info = this.config.logger.info;
|
|
46
29
|
this.config.logger.info = (message, options) => {
|
|
@@ -74,20 +57,18 @@ export class Rebundle {
|
|
|
74
57
|
return;
|
|
75
58
|
// Prepare chunk path and build options
|
|
76
59
|
const chunkPath = $path.join(this.outDir, chunk.fileName);
|
|
77
|
-
const
|
|
78
|
-
const chunkBuildOptions = this.options.bundles?.[chunk.name] ?? {};
|
|
60
|
+
const options = this.options[chunk.name] ?? {};
|
|
79
61
|
// Build with esbuild
|
|
80
62
|
await $esbuild.build({
|
|
81
63
|
minify: Boolean(this.config.build.minify),
|
|
82
64
|
sourcemap: Boolean(this.config.build.sourcemap),
|
|
83
|
-
|
|
65
|
+
...options,
|
|
84
66
|
outfile: chunkPath,
|
|
85
67
|
entryPoints: [chunkPath],
|
|
86
68
|
bundle: true,
|
|
87
69
|
allowOverwrite: true,
|
|
88
70
|
plugins: [
|
|
89
|
-
...(
|
|
90
|
-
...(chunkBuildOptions.plugins ?? []),
|
|
71
|
+
...(options.plugins ?? []),
|
|
91
72
|
{
|
|
92
73
|
name: 'logger',
|
|
93
74
|
setup: build => {
|
|
@@ -128,10 +109,8 @@ export class Rebundle {
|
|
|
128
109
|
// Remove containing directory if empty
|
|
129
110
|
const dir = $path.dirname(path);
|
|
130
111
|
const files = await $fs.readdir(dir);
|
|
131
|
-
if (files.length === 0)
|
|
132
|
-
console.warn(await $fs.stat(dir));
|
|
112
|
+
if (files.length === 0)
|
|
133
113
|
await $fs.rmdir(dir);
|
|
134
|
-
}
|
|
135
114
|
}
|
|
136
115
|
};
|
|
137
116
|
// ---------------------------------------------------------------------------
|
|
@@ -151,11 +130,6 @@ export class Rebundle {
|
|
|
151
130
|
}));
|
|
152
131
|
return content;
|
|
153
132
|
}
|
|
154
|
-
without(object, key) {
|
|
155
|
-
const result = { ...object };
|
|
156
|
-
delete result[key];
|
|
157
|
-
return result;
|
|
158
|
-
}
|
|
159
133
|
get never() {
|
|
160
134
|
throw new Error('never');
|
|
161
135
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-rebundle",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "imkost",
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
"vite-plugin"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"chalk": "^5.6.0"
|
|
28
|
-
"merge-anything": "^6.0.6"
|
|
27
|
+
"chalk": "^5.6.0"
|
|
29
28
|
}
|
|
30
29
|
}
|