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

Document webpack change: feat: add new external type "module-import" #7348

Open
webpack-bot opened this issue Aug 6, 2024 · 0 comments · May be fixed by #7345
Open

Document webpack change: feat: add new external type "module-import" #7348

webpack-bot opened this issue Aug 6, 2024 · 0 comments · May be fixed by #7345

Comments

@webpack-bot
Copy link

A pull request by @fi3ework was merged and maintainers requested a documentation change.

See pull request: webpack/webpack#18620


What kind of change does this PR introduce?

Resolve #17986.

Documentation update: #7345.


Following content maybe somehow out of context. This PR's final implementation is to resolve #17986.

A new external type has been introduced, mainly for the purpose of output clean artifact during bundling library. The name of this "module-import" is referenced from webpack/webpack#17986 (comment), but I'm not sure if the current implementation fully meets the intention of this comment. This PR is an incomplete implementation, only implementing the handling of external processing for dynamic imports.

Here's what it does:

Given following config:

// webpack.config.js
externals: {
  path: 'path node-commonjs',
  fs: 'module-import fs',
  'node:fs': 'module-import node:fs',
  'node-fs': 'module-import fs',
},

source

it("should allow async externals", async () => {
	const fs1 = await import("fs");
	const fs2 = await import("node:fs");
	const fs3 = await import("node-fs");

	expect(fs1).toStrictEqual(fs2);
	expect(fs1).toStrictEqual(fs3);
});

output

var __webpack_exports__ = {};
/*!******************!*\
  !*** ./index.js ***!
  \******************/
it("should allow async externals", async () => {
	const fs1 = await import("fs");
	const fs2 = await import("node:fs");
	const fs3 = await import("fs");

	expect(fs1).toStrictEqual(fs2);
	expect(fs1).toStrictEqual(fs3);
});

There is a slightly hacky bit here, where we're deleting ImportDependency at finishModules stage to prevent any runtime code from being generated. But I couldn't find a better way to prevent ImportDependencyTemplate from modifying the runtime code. Possibly by introducing a new DependencyLibraryTemplate specifically for library patterns could achieve that. Do you have any suggestions on how to suppress runtime code generation? @alexander-akait

Did you add tests for your changes?

Yes.

Does this PR introduce a breaking change?

No.

What needs to be documented once your changes are merged?

The PR is still in draft mode, it should add update the document before merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant