Skip to content

feat: runtime template with dojang - #7764

Closed
LingyuCoder wants to merge 6 commits into
mainfrom
feat/runtime-template
Closed

LingyuCoder wants to merge 6 commits into
mainfrom
feat/runtime-template

Conversation

@LingyuCoder

@LingyuCoder LingyuCoder commented Sep 2, 2024 •

Copy link
Copy Markdown
Contributor

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 rstackjs/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;
};

Checklist

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

@github-actions github-actions Bot added release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack. labels Sep 2, 2024
@netlify

netlify Bot commented Sep 2, 2024 •

Copy link
Copy Markdown

✅ Deploy Preview for rspack ready!

Name Link
🔨 Latest commit 5da2634
🔍 Latest deploy log https://app.netlify.com/sites/rspack/deploys/66d69cf56aa7a60008b293b0
😎 Deploy Preview https://deploy-preview-7764--rspack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@stale

stale Bot commented Nov 2, 2024

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity. If this pull request is still relevant, please leave any comment (for example, "bump").

@stale stale Bot added the stale label Nov 2, 2024
@GiveMe-A-Name

Copy link
Copy Markdown
Member

Continue work another PR #8851

@stale stale Bot removed the stale label Dec 26, 2024
@LingyuCoder
LingyuCoder deleted the feat/runtime-template branch February 14, 2025 09:02
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.

2 participants