Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: integrate rspack_dojang for enhanced template rendering #9079

Merged
merged 1 commit into from
Jan 22, 2025

Conversation

GiveMe-A-Name
Copy link
Member

Summary

Use dojang to render runtime modules, related to #5316

Use dojang because it supports custom function, and we can use the same code in template to generate different result by inject functions according to output.environment, and also html plugin is using it so the package size will not increase.
Inject runtime globals as parameters by default.
Dojang only support string literal so array of strings need to be joined with ,.
relate to rspack-contrib/rspack-dojang#3

for example, the on chunk loaded runtime module can be rendered by template blow:

var deferred = [];
<%= ON_CHUNKS_LOADED %> = <%= basicFunction("result, chunkIds, fn, priority") %> {
	if (chunkIds) {
		priority = priority || 0;
		for (var i = deferred.length; i > 0 && deferred[i - 1][2] > priority; i--)
			deferred[i] = deferred[i - 1];
		deferred[i] = [chunkIds, fn, priority];
		return;
	}
	var notFulfilled = Infinity;
	for (var i = 0; i < deferred.length; i++) {
		<%= destructureArray("chunkIds, fn, priority", "deferred[i]") %>
		var fulfilled = true;
		for (var j = 0; j < chunkIds.length; j++) {
			if (
				(priority & (1 === 0) || notFulfilled >= priority) &&
				Object.keys(<%= ON_CHUNKS_LOADED %>).every(<%= returningFunction(ON_CHUNKS_LOADED + "[key](chunkIds[j])", "key") %>)
			) {
				chunkIds.splice(j--, 1);
			} else {
				fulfilled = false;
				if (priority < notFulfilled) notFulfilled = priority;
			}
		}
		if (fulfilled) {
			deferred.splice(i--, 1);
			var r = fn();
			if (r !== undefined) result = r;
		}
	}
	return result;
};

Fork from #7764

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

- Added rspack_dojang as a workspace dependency in rspack_core.
- Introduced new template functions in RuntimeTemplate for better rendering capabilities.
- Replaced static async module JavaScript with dynamic EJS templates for improved flexibility.
- Enhanced AsyncRuntimeModule to utilize the new template rendering system.
@GiveMe-A-Name GiveMe-A-Name marked this pull request as draft January 22, 2025 03:24
@github-actions github-actions bot added the team The issue/pr is created by the member of Rspack. label Jan 22, 2025
Copy link

netlify bot commented Jan 22, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit dc4069f
🔍 Latest deploy log https://app.netlify.com/sites/rspack/deploys/679064e69e65ff00084e69a4

Copy link

codspeed-hq bot commented Jan 22, 2025

CodSpeed Performance Report

Merging #9079 will not alter performance

Comparing feat/runtime-template-with-dojang (dc4069f) with main (c1819ba)

🎉 Hooray! codspeed-rust just leveled up to 2.7.2!

A heads-up, this is a breaking change and it might affect your current performance baseline a bit. But here's the exciting part - it's packed with new, cool features and promises improved result stability 🥳!
Curious about what's new? Visit our releases page to delve into all the awesome details about this new version.

Summary

✅ 3 untouched benchmarks

@GiveMe-A-Name GiveMe-A-Name marked this pull request as ready for review January 22, 2025 04:02
@GiveMe-A-Name GiveMe-A-Name marked this pull request as draft January 22, 2025 04:03
@GiveMe-A-Name GiveMe-A-Name marked this pull request as ready for review January 22, 2025 06:10
@GiveMe-A-Name GiveMe-A-Name merged commit 2d25168 into main Jan 22, 2025
32 checks passed
@GiveMe-A-Name GiveMe-A-Name deleted the feat/runtime-template-with-dojang branch January 22, 2025 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team The issue/pr is created by the member of Rspack.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants