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

Allow require.context() passing a fixed chunk name #13894

Closed
yyj08070631 opened this issue Jul 30, 2021 · 3 comments
Closed

Allow require.context() passing a fixed chunk name #13894

yyj08070631 opened this issue Jul 30, 2021 · 3 comments

Comments

@yyj08070631
Copy link

Feature request

What is the expected behavior?

Support a syntax like require.context('./modules', true, /\.js$/, 'lazy', 'myModule') to allow specifying a fixed chunkName.

What is motivation or use case for adding/changing the behavior?

I want to split some code and pack them into a single file about operating dialogs from a enormous module.

  • require.context() doesn't support specifying a fixed chunkName.
  • require.ensure() and import() don't support passing expressions as module names.

How should this be implemented in your opinion?

I try to turn webpack\lib\dependencies\RequireContextDependencyParserPlugin.js into a new async-import-plugin. It supports the fifth param which can pass a fixed chunkName. The following is a replaying step.

  • Clone the repo async-import-plugin, run npm i.
  • Modify some code about managing chunkName in webpack\lib\ContextModule.js.
    impicture_20210730_174940
  • Run npm run build, then require.asyncImport('./modules', true, /\.js$/, 'lazy', '$myModule$') in index.js can achieve the target.

Are you willing to work on this yourself?
yes

@webpack-bot
Copy link
Contributor

For maintainers only:

  • webpack-4
  • webpack-5
  • bug
  • critical-bug
  • enhancement
  • documentation
  • performance
  • dependencies
  • question

@yyj08070631
Copy link
Author

For maintainers only:

  • webpack-4
  • webpack-5
  • bug
  • critical-bug
  • enhancement
  • documentation
  • performance
  • dependencies
  • question

@alexander-akait
Copy link
Member

Duplicate #9184

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

No branches or pull requests

3 participants