zephyr-rspack-plugin 0.1.0-next.1 → 0.1.1-next.1
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/README.md +3 -3
- package/dist/package.json +1 -1
- package/dist/rspack-plugin/env-virtual-loader.js +26 -0
- package/dist/rspack-plugin/ze-rspack-plugin.d.ts +3 -2
- package/dist/rspack-plugin/ze-rspack-plugin.js +83 -0
- package/dist/rspack-plugin/ze-rspack-plugin.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
<div align="center">
|
|
4
4
|
|
|
5
|
-
[Zephyr Cloud](https://zephyr-cloud.io) | [Zephyr Docs](https://docs.zephyr-cloud.io/
|
|
5
|
+
[Zephyr Cloud](https://zephyr-cloud.io) | [Zephyr Docs](https://docs.zephyr-cloud.io/bundlers/rspack) | [Discord](https://zephyr-cloud.io/discord) | [Twitter](https://x.com/ZephyrCloudIO) | [LinkedIn](https://www.linkedin.com/company/zephyr-cloud/)
|
|
6
6
|
|
|
7
7
|
<hr/>
|
|
8
8
|
<img src="https://cdn.prod.website-files.com/669061ee3adb95b628c3acda/66981c766e352fe1f57191e2_Opengraph-zephyr.png" alt="Zephyr Logo" />
|
|
9
9
|
</div>
|
|
10
10
|
|
|
11
|
-
An Rspack plugin for deploying applications with Zephyr Cloud. This plugin integrates seamlessly with Rspack's fast bundling to enable deployment of your applications with Module Federation support. Read more from our documentation [here](https://docs.zephyr-cloud.io/
|
|
11
|
+
An Rspack plugin for deploying applications with Zephyr Cloud. This plugin integrates seamlessly with Rspack's fast bundling to enable deployment of your applications with Module Federation support. Read more from our documentation [here](https://docs.zephyr-cloud.io/integrations/react-rspack-nx).
|
|
12
12
|
|
|
13
13
|
## Get Started
|
|
14
14
|
|
|
@@ -18,7 +18,7 @@ The fastest way to get started is to use to use `create-zephyr-apps` to generate
|
|
|
18
18
|
npx create-zephyr-apps@latest
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
For more information please refer to our [documentation](https://docs.zephyr-cloud.io/
|
|
21
|
+
For more information please refer to our [documentation](https://docs.zephyr-cloud.io/bundlers/rspack).
|
|
22
22
|
|
|
23
23
|
## Installation
|
|
24
24
|
|
package/dist/package.json
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Lightweight loader to rewrite ZE_PUBLIC_* env reads to a virtual module import
|
|
2
|
+
// CommonJS to be consumable by Rspack
|
|
3
|
+
|
|
4
|
+
const { rewriteEnvReadsToVirtualModule } = require('zephyr-agent');
|
|
5
|
+
|
|
6
|
+
module.exports = function envVirtualLoader(source) {
|
|
7
|
+
const options = this && typeof this.getOptions === 'function' ? this.getOptions() : {};
|
|
8
|
+
|
|
9
|
+
if (typeof rewriteEnvReadsToVirtualModule !== 'function') {
|
|
10
|
+
return source;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const res = rewriteEnvReadsToVirtualModule(
|
|
15
|
+
String(source),
|
|
16
|
+
options && options.specifier
|
|
17
|
+
);
|
|
18
|
+
if (res && typeof res.code === 'string') {
|
|
19
|
+
return res.code;
|
|
20
|
+
}
|
|
21
|
+
} catch (_e) {
|
|
22
|
+
// fallthrough; return original source if rewrite fails
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return source;
|
|
26
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ZephyrEngine } from 'zephyr-agent';
|
|
2
|
-
import type { ModuleFederationPlugin } from 'zephyr-xpack-internal';
|
|
3
1
|
import type { Compiler } from '@rspack/core';
|
|
2
|
+
import { type ZephyrEngine } from 'zephyr-agent';
|
|
3
|
+
import type { ModuleFederationPlugin } from 'zephyr-xpack-internal';
|
|
4
4
|
export interface ZephyrRspackInternalPluginOptions {
|
|
5
5
|
zephyr_engine: ZephyrEngine;
|
|
6
6
|
pluginName: string;
|
|
@@ -8,6 +8,7 @@ export interface ZephyrRspackInternalPluginOptions {
|
|
|
8
8
|
wait_for_index_html?: boolean;
|
|
9
9
|
}
|
|
10
10
|
export declare class ZeRspackPlugin {
|
|
11
|
+
#private;
|
|
11
12
|
_options: ZephyrRspackInternalPluginOptions;
|
|
12
13
|
constructor(options: Omit<ZephyrRspackInternalPluginOptions, 'pluginName'>);
|
|
13
14
|
apply(compiler: Compiler): void;
|
|
@@ -1,18 +1,101 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _ZeRspackPlugin_instances, _ZeRspackPlugin_convertFederatedDepsToRemotes, _ZeRspackPlugin_injectImportMapAtBuildTime;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.ZeRspackPlugin = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const core_1 = require("@rspack/core");
|
|
7
|
+
const zephyr_agent_1 = require("zephyr-agent");
|
|
4
8
|
const zephyr_xpack_internal_1 = require("zephyr-xpack-internal");
|
|
5
9
|
const pluginName = 'ZeRspackPlugin';
|
|
6
10
|
class ZeRspackPlugin {
|
|
7
11
|
constructor(options) {
|
|
12
|
+
_ZeRspackPlugin_instances.add(this);
|
|
8
13
|
this._options = Object.assign({ pluginName }, options);
|
|
9
14
|
}
|
|
10
15
|
apply(compiler) {
|
|
11
16
|
this._options.zephyr_engine.buildProperties.output = compiler.outputPath;
|
|
12
17
|
(0, zephyr_xpack_internal_1.detectAndStoreBaseHref)(this._options.zephyr_engine, compiler);
|
|
13
18
|
(0, zephyr_xpack_internal_1.logBuildSteps)(this._options, compiler);
|
|
19
|
+
(0, zephyr_xpack_internal_1.setupManifestEmission)(this._options, compiler);
|
|
14
20
|
(0, zephyr_xpack_internal_1.setupZeDeploy)(this._options, compiler);
|
|
21
|
+
// Inject import map into HTML at build time for consistent structure
|
|
22
|
+
tslib_1.__classPrivateFieldGet(this, _ZeRspackPlugin_instances, "m", _ZeRspackPlugin_injectImportMapAtBuildTime).call(this, compiler);
|
|
23
|
+
// Ensure our loader runs on JS/TS to rewrite env reads to virtual module
|
|
24
|
+
const rules = compiler.options?.module?.rules || [];
|
|
25
|
+
rules.unshift({
|
|
26
|
+
test: /\.[jt]sx?$/,
|
|
27
|
+
exclude: /node_modules/,
|
|
28
|
+
use: [
|
|
29
|
+
{
|
|
30
|
+
loader: require.resolve('./env-virtual-loader.js'),
|
|
31
|
+
options: {
|
|
32
|
+
specifier: `env:vars:${this._options.zephyr_engine.applicationProperties.name}`,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
});
|
|
37
|
+
compiler.options.module = compiler.options.module || {};
|
|
38
|
+
compiler.options.module.rules = rules;
|
|
39
|
+
// Mark the virtual specifier external so import maps can resolve it
|
|
40
|
+
const existingExternals = compiler.options?.externals;
|
|
41
|
+
const PER_APP_SPECIFIER = `env:vars:${this._options.zephyr_engine.applicationProperties.name}`;
|
|
42
|
+
const virtualExternal = {
|
|
43
|
+
[PER_APP_SPECIFIER]: `module ${PER_APP_SPECIFIER}`,
|
|
44
|
+
};
|
|
45
|
+
if (!existingExternals) {
|
|
46
|
+
compiler.options.externals = virtualExternal;
|
|
47
|
+
}
|
|
48
|
+
else if (Array.isArray(existingExternals)) {
|
|
49
|
+
compiler.options.externals = [...existingExternals, virtualExternal];
|
|
50
|
+
}
|
|
51
|
+
else if (typeof existingExternals === 'object') {
|
|
52
|
+
compiler.options.externals = {
|
|
53
|
+
...existingExternals,
|
|
54
|
+
...virtualExternal,
|
|
55
|
+
};
|
|
56
|
+
} // function externals not supported here; users can extend if needed
|
|
15
57
|
}
|
|
16
58
|
}
|
|
17
59
|
exports.ZeRspackPlugin = ZeRspackPlugin;
|
|
60
|
+
_ZeRspackPlugin_instances = new WeakSet(), _ZeRspackPlugin_convertFederatedDepsToRemotes = function _ZeRspackPlugin_convertFederatedDepsToRemotes() {
|
|
61
|
+
return (this._options.zephyr_engine.federated_dependencies?.map((dep) => ({
|
|
62
|
+
name: dep.name,
|
|
63
|
+
remote_entry_url: dep.default_url,
|
|
64
|
+
})) || []);
|
|
65
|
+
}, _ZeRspackPlugin_injectImportMapAtBuildTime = function _ZeRspackPlugin_injectImportMapAtBuildTime(compiler) {
|
|
66
|
+
compiler.hooks.compilation.tap(pluginName, (compilation) => {
|
|
67
|
+
// Use HtmlRspackPlugin's proper hooks
|
|
68
|
+
try {
|
|
69
|
+
const hooks = core_1.HtmlRspackPlugin.getCompilationHooks(compilation);
|
|
70
|
+
// Use afterTemplateExecution hook to modify HTML and tags
|
|
71
|
+
hooks.afterTemplateExecution.tapPromise(pluginName, async (data) => {
|
|
72
|
+
try {
|
|
73
|
+
const appName = this._options.zephyr_engine.applicationProperties.name;
|
|
74
|
+
const remotes = tslib_1.__classPrivateFieldGet(this, _ZeRspackPlugin_instances, "m", _ZeRspackPlugin_convertFederatedDepsToRemotes).call(this);
|
|
75
|
+
// Check if import map already exists
|
|
76
|
+
const hasImportMap = data.headTags.some((tag) => tag.tagName === 'script' && tag.attributes?.type === 'importmap');
|
|
77
|
+
if (!hasImportMap) {
|
|
78
|
+
// Add import map to head tags
|
|
79
|
+
data.headTags.unshift({
|
|
80
|
+
tagName: 'script',
|
|
81
|
+
attributes: { type: 'importmap' },
|
|
82
|
+
innerHTML: JSON.stringify({
|
|
83
|
+
imports: (0, zephyr_agent_1.buildEnvImportMap)(appName, remotes),
|
|
84
|
+
}),
|
|
85
|
+
voidTag: false,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
console.warn('Failed to inject import map at build time:', e);
|
|
91
|
+
}
|
|
92
|
+
return data;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
// HtmlRspackPlugin might not be available if no HTML is being generated
|
|
97
|
+
console.log('HtmlRspackPlugin not available, skipping import map injection');
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
};
|
|
18
101
|
//# sourceMappingURL=ze-rspack-plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ze-rspack-plugin.js","sourceRoot":"","sources":["../../src/rspack-plugin/ze-rspack-plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ze-rspack-plugin.js","sourceRoot":"","sources":["../../src/rspack-plugin/ze-rspack-plugin.ts"],"names":[],"mappings":";;;;;AACA,uCAAgD;AAChD,+CAAsF;AAEtF,iEAK+B;AAE/B,MAAM,UAAU,GAAG,gBAAgB,CAAC;AAapC,MAAa,cAAc;IAGzB,YAAY,OAA8D;;QACxE,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,EAAE,OAAO,CAAC,CAAC;IACzD,CAAC;IAED,KAAK,CAAC,QAAkB;QACtB,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,eAAe,CAAC,MAAM,GAAG,QAAQ,CAAC,UAAU,CAAC;QACzE,IAAA,8CAAsB,EAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;QAC9D,IAAA,qCAAa,EAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACvC,IAAA,6CAAqB,EAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC/C,IAAA,qCAAa,EAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAEvC,qEAAqE;QACrE,+BAAA,IAAI,6EAA4B,MAAhC,IAAI,EAA6B,QAAQ,CAAC,CAAC;QAE3C,yEAAyE;QACzE,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC;QACpD,KAAK,CAAC,OAAO,CAAC;YACZ,IAAI,EAAE,YAAY;YAClB,OAAO,EAAE,cAAc;YACvB,GAAG,EAAE;gBACH;oBACE,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,yBAAyB,CAAC;oBAClD,OAAO,EAAE;wBACP,S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,CAAC,CAAC,CAAC;QACL,CAAC;QAAC,MAAM,CAAC;YACP,wEAAwE;YACxE,OAAO,CAAC,GAAG,CAAC,+DAA+D,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zephyr-rspack-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1-next.1",
|
|
4
4
|
"description": "Repack plugin for Zephyr",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"@rspack/core": "^1.5.5",
|
|
21
21
|
"is-ci": "^4.1.0",
|
|
22
22
|
"tslib": "^2.8.1",
|
|
23
|
-
"zephyr-xpack-internal": "0.1.
|
|
24
|
-
"zephyr-agent": "0.1.
|
|
23
|
+
"zephyr-xpack-internal": "0.1.1-next.1",
|
|
24
|
+
"zephyr-agent": "0.1.1-next.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/is-ci": "3.0.4",
|