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: runtime template with dojang #8851

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

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).

@GiveMe-A-Name GiveMe-A-Name marked this pull request as draft December 26, 2024 03:37
@github-actions github-actions bot added the release: feature release: feature related release(mr only) label Dec 26, 2024
Copy link

netlify bot commented Dec 26, 2024

Deploy Preview for rspack canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit aa058b5
🔍 Latest deploy log https://app.netlify.com/sites/rspack/deploys/6789fbb25aa6cb00087af4e6

@GiveMe-A-Name GiveMe-A-Name added the team The issue/pr is created by the member of Rspack. label Dec 26, 2024
Copy link

codspeed-hq bot commented Dec 26, 2024

CodSpeed Performance Report

Merging #8851 will not alter performance

Comparing GiveMe-A-Name:qixuan/runtime-template (aa058b5) with main (8d6406d)

Summary

✅ 3 untouched benchmarks

@GiveMe-A-Name GiveMe-A-Name force-pushed the qixuan/runtime-template branch from 474169e to 8ceb776 Compare December 27, 2024 07:31
@GiveMe-A-Name GiveMe-A-Name force-pushed the qixuan/runtime-template branch 3 times, most recently from b1ea775 to a3e3856 Compare January 13, 2025 06:23
@GiveMe-A-Name GiveMe-A-Name marked this pull request as ready for review January 13, 2025 06:36
@LingyuCoder
Copy link
Contributor

You can add a new test processor which extends RuntimeDiffProcessor with enabling all the output.environments to compare the generated runtime code with webpack.

@GiveMe-A-Name
Copy link
Member Author

You can add a new test processor which extends RuntimeDiffProcessor with enabling all the output.environments to compare the generated runtime code with webpack.

Done~

@GiveMe-A-Name GiveMe-A-Name force-pushed the qixuan/runtime-template branch from 3a0b050 to 34720a9 Compare January 17, 2025 03:38
@CLAassistant
Copy link

CLAassistant commented Jan 17, 2025

CLA assistant check
All committers have signed the CLA.

@GiveMe-A-Name GiveMe-A-Name force-pushed the qixuan/runtime-template branch from ff68d97 to 074d8bc Compare January 17, 2025 06:34
@GiveMe-A-Name GiveMe-A-Name marked this pull request as draft January 20, 2025 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants