@rspack/core 1.0.0-rc.2 → 1.0.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/dist/Compiler.js
CHANGED
|
@@ -786,6 +786,55 @@ _Compiler_instance = new WeakMap(), _Compiler_initial = new WeakMap(), _Compiler
|
|
|
786
786
|
queried.call(Chunk_1.Chunk.__from_binding(chunk, __classPrivateFieldGet(this, _Compiler_compilation, "f")), hash);
|
|
787
787
|
const digestResult = hash.digest(this.options.output.hashDigest);
|
|
788
788
|
return Buffer.from(digestResult);
|
|
789
|
+
}),
|
|
790
|
+
registerHtmlPluginBeforeAssetTagGenerationTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.HtmlPluginBeforeAssetTagGeneration, () => builtin_plugin_1.HtmlRspackPlugin.getCompilationHooks(__classPrivateFieldGet(this, _Compiler_compilation, "f"))
|
|
791
|
+
.beforeAssetTagGeneration, queried => async (data) => {
|
|
792
|
+
return await queried.promise({
|
|
793
|
+
...data,
|
|
794
|
+
plugin: {
|
|
795
|
+
options: builtin_plugin_1.HtmlRspackPlugin.getCompilationOptions(__classPrivateFieldGet(this, _Compiler_compilation, "f")) ||
|
|
796
|
+
{}
|
|
797
|
+
}
|
|
798
|
+
});
|
|
799
|
+
}),
|
|
800
|
+
registerHtmlPluginAlterAssetTagsTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.HtmlPluginAlterAssetTags, () => builtin_plugin_1.HtmlRspackPlugin.getCompilationHooks(__classPrivateFieldGet(this, _Compiler_compilation, "f"))
|
|
801
|
+
.alterAssetTags, queried => async (data) => {
|
|
802
|
+
return await queried.promise(data);
|
|
803
|
+
}),
|
|
804
|
+
registerHtmlPluginAlterAssetTagGroupsTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.HtmlPluginAlterAssetTagGroups, () => builtin_plugin_1.HtmlRspackPlugin.getCompilationHooks(__classPrivateFieldGet(this, _Compiler_compilation, "f"))
|
|
805
|
+
.alterAssetTagGroups, queried => async (data) => {
|
|
806
|
+
return await queried.promise({
|
|
807
|
+
...data,
|
|
808
|
+
plugin: {
|
|
809
|
+
options: builtin_plugin_1.HtmlRspackPlugin.getCompilationOptions(__classPrivateFieldGet(this, _Compiler_compilation, "f")) || {}
|
|
810
|
+
}
|
|
811
|
+
});
|
|
812
|
+
}),
|
|
813
|
+
registerHtmlPluginAfterTemplateExecutionTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.HtmlPluginAfterTemplateExecution, () => builtin_plugin_1.HtmlRspackPlugin.getCompilationHooks(__classPrivateFieldGet(this, _Compiler_compilation, "f"))
|
|
814
|
+
.afterTemplateExecution, queried => async (data) => {
|
|
815
|
+
return await queried.promise({
|
|
816
|
+
...data,
|
|
817
|
+
plugin: {
|
|
818
|
+
options: builtin_plugin_1.HtmlRspackPlugin.getCompilationOptions(__classPrivateFieldGet(this, _Compiler_compilation, "f")) ||
|
|
819
|
+
{}
|
|
820
|
+
}
|
|
821
|
+
});
|
|
822
|
+
}),
|
|
823
|
+
registerHtmlPluginBeforeEmitTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.HtmlPluginBeforeEmit, () => builtin_plugin_1.HtmlRspackPlugin.getCompilationHooks(__classPrivateFieldGet(this, _Compiler_compilation, "f")).beforeEmit, queried => async (data) => {
|
|
824
|
+
return await queried.promise({
|
|
825
|
+
...data,
|
|
826
|
+
plugin: {
|
|
827
|
+
options: builtin_plugin_1.HtmlRspackPlugin.getCompilationOptions(__classPrivateFieldGet(this, _Compiler_compilation, "f")) || {}
|
|
828
|
+
}
|
|
829
|
+
});
|
|
830
|
+
}),
|
|
831
|
+
registerHtmlPluginAfterEmitTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.HtmlPluginAfterEmit, () => builtin_plugin_1.HtmlRspackPlugin.getCompilationHooks(__classPrivateFieldGet(this, _Compiler_compilation, "f")).afterEmit, queried => async (data) => {
|
|
832
|
+
return await queried.promise({
|
|
833
|
+
...data,
|
|
834
|
+
plugin: {
|
|
835
|
+
options: builtin_plugin_1.HtmlRspackPlugin.getCompilationOptions(__classPrivateFieldGet(this, _Compiler_compilation, "f")) || {}
|
|
836
|
+
}
|
|
837
|
+
});
|
|
789
838
|
})
|
|
790
839
|
}, "f");
|
|
791
840
|
__classPrivateFieldSet(this, _Compiler_instance, new instanceBinding.Rspack(rawOptions, __classPrivateFieldGet(this, _Compiler_builtinPlugins, "f"), __classPrivateFieldGet(this, _Compiler_registers, "f"), FileSystem_1.ThreadsafeWritableNodeFS.__to_binding(this.outputFileSystem), ResolverFactory_1.ResolverFactory.__to_binding(this.resolverFactory)), "f");
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { BuiltinPluginName } from "@rspack/binding";
|
|
1
|
+
import { BuiltinPluginName, type JsAfterEmitData, type JsAfterTemplateExecutionData, type JsAlterAssetTagGroupsData, type JsAlterAssetTagsData, type JsBeforeAssetTagGenerationData, type JsBeforeEmitData, type JsHtmlPluginTag } from "@rspack/binding";
|
|
2
|
+
import * as liteTapable from "@rspack/lite-tapable";
|
|
2
3
|
import { z } from "../../compiled/zod";
|
|
4
|
+
import { Compilation } from "../Compilation";
|
|
5
|
+
import type { Compiler } from "../Compiler";
|
|
3
6
|
declare const htmlRspackPluginOptions: z.ZodObject<{
|
|
4
7
|
filename: z.ZodOptional<z.ZodString>;
|
|
5
|
-
template: z.ZodOptional<z.ZodString
|
|
6
|
-
templateContent: z.ZodOptional<z.ZodString
|
|
7
|
-
templateParameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
8
|
+
template: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
9
|
+
templateContent: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodFunction<z.ZodTuple<[z.ZodRecord<z.ZodString, z.ZodAny>], z.ZodUnknown>, z.ZodUnion<[z.ZodString, z.ZodPromise<z.ZodString>]>>]>>;
|
|
10
|
+
templateParameters: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodString>, z.ZodBoolean]>, z.ZodFunction<z.ZodTuple<[z.ZodRecord<z.ZodString, z.ZodAny>], z.ZodUnknown>, z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodPromise<z.ZodRecord<z.ZodString, z.ZodAny>>]>>]>>;
|
|
8
11
|
inject: z.ZodOptional<z.ZodUnion<[z.ZodEnum<["head", "body"]>, z.ZodBoolean]>>;
|
|
9
12
|
publicPath: z.ZodOptional<z.ZodString>;
|
|
10
13
|
base: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
@@ -32,8 +35,8 @@ declare const htmlRspackPluginOptions: z.ZodObject<{
|
|
|
32
35
|
hash?: boolean | undefined;
|
|
33
36
|
chunks?: string[] | undefined;
|
|
34
37
|
template?: string | undefined;
|
|
35
|
-
templateContent?: string | undefined;
|
|
36
|
-
templateParameters?: Record<string, string> | undefined;
|
|
38
|
+
templateContent?: string | ((args_0: Record<string, any>, ...args_1: unknown[]) => string | Promise<string>) | undefined;
|
|
39
|
+
templateParameters?: boolean | Record<string, string> | ((args_0: Record<string, any>, ...args_1: unknown[]) => Record<string, any> | Promise<Record<string, any>>) | undefined;
|
|
37
40
|
inject?: boolean | "head" | "body" | undefined;
|
|
38
41
|
base?: string | {
|
|
39
42
|
target?: "_self" | "_blank" | "_parent" | "_top" | undefined;
|
|
@@ -52,8 +55,8 @@ declare const htmlRspackPluginOptions: z.ZodObject<{
|
|
|
52
55
|
hash?: boolean | undefined;
|
|
53
56
|
chunks?: string[] | undefined;
|
|
54
57
|
template?: string | undefined;
|
|
55
|
-
templateContent?: string | undefined;
|
|
56
|
-
templateParameters?: Record<string, string> | undefined;
|
|
58
|
+
templateContent?: string | ((args_0: Record<string, any>, ...args_1: unknown[]) => string | Promise<string>) | undefined;
|
|
59
|
+
templateParameters?: boolean | Record<string, string> | ((args_0: Record<string, any>, ...args_1: unknown[]) => Record<string, any> | Promise<Record<string, any>>) | undefined;
|
|
57
60
|
inject?: boolean | "head" | "body" | undefined;
|
|
58
61
|
base?: string | {
|
|
59
62
|
target?: "_self" | "_blank" | "_parent" | "_top" | undefined;
|
|
@@ -68,15 +71,38 @@ declare const htmlRspackPluginOptions: z.ZodObject<{
|
|
|
68
71
|
meta?: Record<string, string | Record<string, string>> | undefined;
|
|
69
72
|
}>;
|
|
70
73
|
export type HtmlRspackPluginOptions = z.infer<typeof htmlRspackPluginOptions>;
|
|
71
|
-
|
|
74
|
+
type ExtraPluginHookData = {
|
|
75
|
+
plugin: {
|
|
76
|
+
options: HtmlRspackPluginOptions;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
export type HtmlRspackPluginHooks = {
|
|
80
|
+
beforeAssetTagGeneration: liteTapable.AsyncSeriesWaterfallHook<[
|
|
81
|
+
JsBeforeAssetTagGenerationData & ExtraPluginHookData
|
|
82
|
+
]>;
|
|
83
|
+
alterAssetTags: liteTapable.AsyncSeriesWaterfallHook<[JsAlterAssetTagsData]>;
|
|
84
|
+
alterAssetTagGroups: liteTapable.AsyncSeriesWaterfallHook<[
|
|
85
|
+
JsAlterAssetTagGroupsData & ExtraPluginHookData
|
|
86
|
+
]>;
|
|
87
|
+
afterTemplateExecution: liteTapable.AsyncSeriesWaterfallHook<[
|
|
88
|
+
JsAfterTemplateExecutionData & ExtraPluginHookData
|
|
89
|
+
]>;
|
|
90
|
+
beforeEmit: liteTapable.AsyncSeriesWaterfallHook<[
|
|
91
|
+
JsBeforeEmitData & ExtraPluginHookData
|
|
92
|
+
]>;
|
|
93
|
+
afterEmit: liteTapable.AsyncSeriesWaterfallHook<[
|
|
94
|
+
JsAfterEmitData & ExtraPluginHookData
|
|
95
|
+
]>;
|
|
96
|
+
};
|
|
97
|
+
declare const HtmlRspackPlugin: {
|
|
72
98
|
new (c?: {
|
|
73
99
|
filename?: string | undefined;
|
|
74
100
|
publicPath?: string | undefined;
|
|
75
101
|
hash?: boolean | undefined;
|
|
76
102
|
chunks?: string[] | undefined;
|
|
77
103
|
template?: string | undefined;
|
|
78
|
-
templateContent?: string | undefined;
|
|
79
|
-
templateParameters?: Record<string, string> | undefined;
|
|
104
|
+
templateContent?: string | ((args_0: Record<string, any>, ...args_1: unknown[]) => string | Promise<string>) | undefined;
|
|
105
|
+
templateParameters?: boolean | Record<string, string> | ((args_0: Record<string, any>, ...args_1: unknown[]) => Record<string, any> | Promise<Record<string, any>>) | undefined;
|
|
80
106
|
inject?: boolean | "head" | "body" | undefined;
|
|
81
107
|
base?: string | {
|
|
82
108
|
target?: "_self" | "_blank" | "_parent" | "_top" | undefined;
|
|
@@ -97,8 +123,8 @@ export declare const HtmlRspackPlugin: {
|
|
|
97
123
|
hash?: boolean | undefined;
|
|
98
124
|
chunks?: string[] | undefined;
|
|
99
125
|
template?: string | undefined;
|
|
100
|
-
templateContent?: string | undefined;
|
|
101
|
-
templateParameters?: Record<string, string> | undefined;
|
|
126
|
+
templateContent?: string | ((args_0: Record<string, any>, ...args_1: unknown[]) => string | Promise<string>) | undefined;
|
|
127
|
+
templateParameters?: boolean | Record<string, string> | ((args_0: Record<string, any>, ...args_1: unknown[]) => Record<string, any> | Promise<Record<string, any>>) | undefined;
|
|
102
128
|
inject?: boolean | "head" | "body" | undefined;
|
|
103
129
|
base?: string | {
|
|
104
130
|
target?: "_self" | "_blank" | "_parent" | "_top" | undefined;
|
|
@@ -113,8 +139,12 @@ export declare const HtmlRspackPlugin: {
|
|
|
113
139
|
meta?: Record<string, string | Record<string, string>> | undefined;
|
|
114
140
|
} | undefined];
|
|
115
141
|
affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined;
|
|
116
|
-
raw(compiler:
|
|
117
|
-
apply(compiler:
|
|
142
|
+
raw(compiler: Compiler): import("@rspack/binding").BuiltinPlugin;
|
|
143
|
+
apply(compiler: Compiler): void;
|
|
118
144
|
};
|
|
145
|
+
} & {
|
|
146
|
+
getCompilationHooks: (compilation: Compilation) => HtmlRspackPluginHooks;
|
|
147
|
+
getCompilationOptions: (compilation: Compilation) => HtmlRspackPluginOptions | void;
|
|
148
|
+
createHtmlTagObject: (tagName: string, attributes?: Record<string, string | boolean>, innerHTML?: string | undefined) => JsHtmlPluginTag;
|
|
119
149
|
};
|
|
120
|
-
export {};
|
|
150
|
+
export { HtmlRspackPlugin };
|
|
@@ -1,15 +1,62 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
2
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
29
|
exports.HtmlRspackPlugin = void 0;
|
|
30
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
31
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
4
32
|
const binding_1 = require("@rspack/binding");
|
|
33
|
+
const liteTapable = __importStar(require("@rspack/lite-tapable"));
|
|
5
34
|
const zod_1 = require("../../compiled/zod");
|
|
35
|
+
const Compilation_1 = require("../Compilation");
|
|
6
36
|
const validate_1 = require("../util/validate");
|
|
7
37
|
const base_1 = require("./base");
|
|
38
|
+
const templateRenderFunction = zod_1.z
|
|
39
|
+
.function()
|
|
40
|
+
.args(zod_1.z.record(zod_1.z.string(), zod_1.z.any()))
|
|
41
|
+
.returns(zod_1.z.string().or(zod_1.z.promise(zod_1.z.string())));
|
|
42
|
+
const templateParamFunction = zod_1.z
|
|
43
|
+
.function()
|
|
44
|
+
.args(zod_1.z.record(zod_1.z.string(), zod_1.z.any()))
|
|
45
|
+
.returns(zod_1.z.record(zod_1.z.string(), zod_1.z.any()).or(zod_1.z.promise(zod_1.z.record(zod_1.z.string(), zod_1.z.any()))));
|
|
8
46
|
const htmlRspackPluginOptions = zod_1.z.strictObject({
|
|
9
47
|
filename: zod_1.z.string().optional(),
|
|
10
|
-
template: zod_1.z
|
|
11
|
-
|
|
12
|
-
|
|
48
|
+
template: zod_1.z
|
|
49
|
+
.string()
|
|
50
|
+
.refine(val => !val.includes("!"), () => ({
|
|
51
|
+
message: "HtmlRspackPlugin does not support template path with loader yet"
|
|
52
|
+
}))
|
|
53
|
+
.optional(),
|
|
54
|
+
templateContent: zod_1.z.string().or(templateRenderFunction).optional(),
|
|
55
|
+
templateParameters: zod_1.z
|
|
56
|
+
.record(zod_1.z.string())
|
|
57
|
+
.or(zod_1.z.boolean())
|
|
58
|
+
.or(templateParamFunction)
|
|
59
|
+
.optional(),
|
|
13
60
|
inject: zod_1.z.enum(["head", "body"]).or(zod_1.z.boolean()).optional(),
|
|
14
61
|
publicPath: zod_1.z.string().optional(),
|
|
15
62
|
base: zod_1.z
|
|
@@ -31,7 +78,7 @@ const htmlRspackPluginOptions = zod_1.z.strictObject({
|
|
|
31
78
|
meta: zod_1.z.record(zod_1.z.string().or(zod_1.z.record(zod_1.z.string()))).optional(),
|
|
32
79
|
hash: zod_1.z.boolean().optional()
|
|
33
80
|
});
|
|
34
|
-
|
|
81
|
+
const HtmlRspackPluginImpl = (0, base_1.create)(binding_1.BuiltinPluginName.HtmlRspackPlugin, function (c = {}) {
|
|
35
82
|
(0, validate_1.validate)(c, htmlRspackPluginOptions);
|
|
36
83
|
const meta = {};
|
|
37
84
|
for (const key in c.meta) {
|
|
@@ -59,11 +106,180 @@ exports.HtmlRspackPlugin = (0, base_1.create)(binding_1.BuiltinPluginName.HtmlRs
|
|
|
59
106
|
? "false"
|
|
60
107
|
: configInject;
|
|
61
108
|
const base = typeof c.base === "string" ? { href: c.base } : c.base;
|
|
109
|
+
let compilation = null;
|
|
110
|
+
this.hooks.compilation.tap("HtmlRspackPlugin", compilationInstance => {
|
|
111
|
+
compilation = compilationInstance;
|
|
112
|
+
compilationOptionsMap.set(compilation, c);
|
|
113
|
+
});
|
|
114
|
+
this.hooks.done.tap("HtmlRspackPlugin", stats => {
|
|
115
|
+
compilationHooksMap.delete(stats.compilation);
|
|
116
|
+
compilationOptionsMap.delete(stats.compilation);
|
|
117
|
+
});
|
|
118
|
+
function generateRenderData(data) {
|
|
119
|
+
const json = JSON.parse(data);
|
|
120
|
+
if (typeof c.templateParameters !== "function") {
|
|
121
|
+
json.compilation = compilation;
|
|
122
|
+
}
|
|
123
|
+
const renderTag = function () {
|
|
124
|
+
return htmlTagObjectToString(this);
|
|
125
|
+
};
|
|
126
|
+
const renderTagList = function () {
|
|
127
|
+
return this.join("");
|
|
128
|
+
};
|
|
129
|
+
if (Array.isArray(json.htmlRspackPlugin?.tags?.headTags)) {
|
|
130
|
+
for (const tag of json.htmlRspackPlugin.tags.headTags) {
|
|
131
|
+
tag.toString = renderTag;
|
|
132
|
+
}
|
|
133
|
+
json.htmlRspackPlugin.tags.headTags.toString = renderTagList;
|
|
134
|
+
}
|
|
135
|
+
if (Array.isArray(json.htmlRspackPlugin?.tags?.bodyTags)) {
|
|
136
|
+
for (const tag of json.htmlRspackPlugin.tags.bodyTags) {
|
|
137
|
+
tag.toString = renderTag;
|
|
138
|
+
}
|
|
139
|
+
json.htmlRspackPlugin.tags.bodyTags.toString = renderTagList;
|
|
140
|
+
}
|
|
141
|
+
return json;
|
|
142
|
+
}
|
|
143
|
+
let templateContent = c.templateContent;
|
|
144
|
+
let templateFn = undefined;
|
|
145
|
+
if (typeof templateContent === "function") {
|
|
146
|
+
templateFn = async (data) => {
|
|
147
|
+
try {
|
|
148
|
+
const renderer = c.templateContent;
|
|
149
|
+
if (c.templateParameters === false) {
|
|
150
|
+
return await renderer({});
|
|
151
|
+
}
|
|
152
|
+
return await renderer(generateRenderData(data));
|
|
153
|
+
}
|
|
154
|
+
catch (e) {
|
|
155
|
+
const error = new Error(`HtmlRspackPlugin: render template function failed, ${e.message}`);
|
|
156
|
+
error.stack = e.stack;
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
templateContent = "";
|
|
161
|
+
}
|
|
162
|
+
else if (c.template) {
|
|
163
|
+
const filename = c.template.split("?")[0];
|
|
164
|
+
if ([".js", ".cjs"].includes(node_path_1.default.extname(filename))) {
|
|
165
|
+
templateFn = async (data) => {
|
|
166
|
+
const context = this.options.context || process.cwd();
|
|
167
|
+
const templateFilePath = node_path_1.default.resolve(context, filename);
|
|
168
|
+
if (!node_fs_1.default.existsSync(templateFilePath)) {
|
|
169
|
+
throw new Error(`HtmlRspackPlugin: could not load file \`${filename}\` from \`${context}\``);
|
|
170
|
+
}
|
|
171
|
+
try {
|
|
172
|
+
const renderer = require(templateFilePath);
|
|
173
|
+
if (c.templateParameters === false) {
|
|
174
|
+
return await renderer({});
|
|
175
|
+
}
|
|
176
|
+
return await renderer(generateRenderData(data));
|
|
177
|
+
}
|
|
178
|
+
catch (e) {
|
|
179
|
+
const error = new Error(`HtmlRspackPlugin: render template function failed, ${e.message}`);
|
|
180
|
+
error.stack = e.stack;
|
|
181
|
+
throw error;
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const rawTemplateParameters = c.templateParameters;
|
|
187
|
+
let templateParameters;
|
|
188
|
+
if (typeof rawTemplateParameters === "function") {
|
|
189
|
+
templateParameters = async (data) => {
|
|
190
|
+
const newData = await rawTemplateParameters(JSON.parse(data));
|
|
191
|
+
return JSON.stringify(newData);
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
templateParameters = rawTemplateParameters;
|
|
196
|
+
}
|
|
62
197
|
return {
|
|
63
|
-
|
|
198
|
+
filename: c.filename,
|
|
199
|
+
template: c.template,
|
|
200
|
+
hash: c.hash,
|
|
201
|
+
title: c.title,
|
|
202
|
+
favicon: c.favicon,
|
|
203
|
+
publicPath: c.publicPath,
|
|
204
|
+
chunks: c.chunks,
|
|
205
|
+
excludeChunks: c.excludeChunks,
|
|
206
|
+
sri: c.sri,
|
|
207
|
+
minify: c.minify,
|
|
64
208
|
meta,
|
|
65
209
|
scriptLoading,
|
|
66
210
|
inject,
|
|
67
|
-
base
|
|
211
|
+
base,
|
|
212
|
+
templateFn,
|
|
213
|
+
templateContent,
|
|
214
|
+
templateParameters
|
|
68
215
|
};
|
|
69
216
|
});
|
|
217
|
+
function htmlTagObjectToString(tag) {
|
|
218
|
+
const attributes = Object.keys(tag.attributes || {})
|
|
219
|
+
.filter(attributeName => tag.attributes[attributeName] === "" || tag.attributes[attributeName])
|
|
220
|
+
.map(attributeName => {
|
|
221
|
+
if (tag.attributes[attributeName] === "true") {
|
|
222
|
+
return attributeName;
|
|
223
|
+
}
|
|
224
|
+
return `${attributeName}="${tag.attributes[attributeName]}"`;
|
|
225
|
+
});
|
|
226
|
+
const res = `<${[tag.tagName].concat(attributes).join(" ")}${tag.voidTag && !tag.innerHTML ? "/" : ""}>${tag.innerHTML || ""}${tag.voidTag && !tag.innerHTML ? "" : `</${tag.tagName}>`}`;
|
|
227
|
+
return res;
|
|
228
|
+
}
|
|
229
|
+
const compilationHooksMap = new WeakMap();
|
|
230
|
+
const compilationOptionsMap = new WeakMap();
|
|
231
|
+
const HtmlRspackPlugin = HtmlRspackPluginImpl;
|
|
232
|
+
exports.HtmlRspackPlugin = HtmlRspackPlugin;
|
|
233
|
+
const voidTags = [
|
|
234
|
+
"area",
|
|
235
|
+
"base",
|
|
236
|
+
"br",
|
|
237
|
+
"col",
|
|
238
|
+
"embed",
|
|
239
|
+
"hr",
|
|
240
|
+
"img",
|
|
241
|
+
"input",
|
|
242
|
+
"keygen",
|
|
243
|
+
"link",
|
|
244
|
+
"meta",
|
|
245
|
+
"param",
|
|
246
|
+
"source",
|
|
247
|
+
"track",
|
|
248
|
+
"wbr"
|
|
249
|
+
];
|
|
250
|
+
HtmlRspackPlugin.createHtmlTagObject = (tagName, attributes, innerHTML) => {
|
|
251
|
+
return {
|
|
252
|
+
tagName,
|
|
253
|
+
voidTag: voidTags.includes(tagName),
|
|
254
|
+
attributes: attributes || {},
|
|
255
|
+
innerHTML
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
HtmlRspackPlugin.getCompilationOptions = (compilation) => {
|
|
259
|
+
if (!(compilation instanceof Compilation_1.Compilation)) {
|
|
260
|
+
throw new TypeError("The 'compilation' argument must be an instance of Compilation");
|
|
261
|
+
}
|
|
262
|
+
return compilationOptionsMap.get(compilation);
|
|
263
|
+
};
|
|
264
|
+
HtmlRspackPlugin.getCompilationHooks = (compilation) => {
|
|
265
|
+
if (!(compilation instanceof Compilation_1.Compilation)) {
|
|
266
|
+
throw new TypeError("The 'compilation' argument must be an instance of Compilation");
|
|
267
|
+
}
|
|
268
|
+
let hooks = compilationHooksMap.get(compilation);
|
|
269
|
+
if (hooks === undefined) {
|
|
270
|
+
hooks = {
|
|
271
|
+
beforeAssetTagGeneration: new liteTapable.AsyncSeriesWaterfallHook([
|
|
272
|
+
"data"
|
|
273
|
+
]),
|
|
274
|
+
alterAssetTags: new liteTapable.AsyncSeriesWaterfallHook(["data"]),
|
|
275
|
+
alterAssetTagGroups: new liteTapable.AsyncSeriesWaterfallHook(["data"]),
|
|
276
|
+
afterTemplateExecution: new liteTapable.AsyncSeriesWaterfallHook([
|
|
277
|
+
"data"
|
|
278
|
+
]),
|
|
279
|
+
beforeEmit: new liteTapable.AsyncSeriesWaterfallHook(["data"]),
|
|
280
|
+
afterEmit: new liteTapable.AsyncSeriesWaterfallHook(["data"])
|
|
281
|
+
};
|
|
282
|
+
compilationHooksMap.set(compilation, hooks);
|
|
283
|
+
}
|
|
284
|
+
return hooks;
|
|
285
|
+
};
|
|
@@ -55,7 +55,12 @@ function createRawModuleRuleUsesImpl(uses, path, options) {
|
|
|
55
55
|
let isBuiltin = false;
|
|
56
56
|
if (use.loader.startsWith(exports.BUILTIN_LOADER_PREFIX)) {
|
|
57
57
|
o = getBuiltinLoaderOptions(use.loader, use.options, options);
|
|
58
|
-
|
|
58
|
+
// keep json with indent so miette can show pretty error
|
|
59
|
+
o = (0, util_1.isNil)(o)
|
|
60
|
+
? undefined
|
|
61
|
+
: typeof o === "string"
|
|
62
|
+
? o
|
|
63
|
+
: JSON.stringify(o, null, 2);
|
|
59
64
|
isBuiltin = true;
|
|
60
65
|
}
|
|
61
66
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"webpackVersion": "5.75.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "The fast Rust-based web bundler with webpack-compatible API",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@swc/core": "1.4.0",
|
|
40
|
+
"@types/graceful-fs": "4.1.9",
|
|
40
41
|
"@types/neo-async": "^2.6.6",
|
|
41
42
|
"@types/watchpack": "^2.4.0",
|
|
42
43
|
"@types/webpack-sources": "3.2.3",
|
|
@@ -44,15 +45,14 @@
|
|
|
44
45
|
"cross-env": "^7.0.3",
|
|
45
46
|
"enhanced-resolve": "5.12.0",
|
|
46
47
|
"graceful-fs": "4.2.10",
|
|
47
|
-
"@types/graceful-fs": "4.1.9",
|
|
48
48
|
"json-parse-even-better-errors": "^3.0.0",
|
|
49
49
|
"neo-async": "2.6.2",
|
|
50
50
|
"prebundle": "^1.1.0",
|
|
51
|
-
"typescript": "5.0.2",
|
|
52
51
|
"tsc-alias": "^1.8.8",
|
|
52
|
+
"typescript": "5.0.2",
|
|
53
53
|
"watchpack": "^2.4.0",
|
|
54
|
-
"webpack-sources": "3.2.3",
|
|
55
54
|
"webpack-dev-server": "^5.0.4",
|
|
55
|
+
"webpack-sources": "3.2.3",
|
|
56
56
|
"zod": "^3.23.8",
|
|
57
57
|
"zod-validation-error": "3.3.1"
|
|
58
58
|
},
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@module-federation/runtime-tools": "0.5.1",
|
|
61
61
|
"@rspack/lite-tapable": "1.0.0",
|
|
62
62
|
"caniuse-lite": "^1.0.30001616",
|
|
63
|
-
"@rspack/binding": "1.0.
|
|
63
|
+
"@rspack/binding": "1.0.1"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"@swc/helpers": ">=0.5.1"
|