Closed hyf0 closed 1 year ago
I would have use a more complex Regex
\/\* (?:web|rs)packChunkName:\s+(["'`]?)((?:\.\/)?(?:\w[\w0-9\/\-]+)(?:[\w0-9\-]))\1\s+\*\/
(2nd group has to be used, 1st one is for quotes) This one is not perfect either, but it allows:
rspackChunkName
or webpackChunkName
-
and _
in folder/file nameWonderful guidance comes from @lalexdotcom in https://github.com/web-infra-dev/rspack/pull/2686#issuecomment-1503366533.
what is the difference between webpackchunkname and rspackchunkname
what is the difference between webpackchunkname and rspackchunkname
The characters :)
then i dont think it is necessary to support this, every unnecessary new api comes with a burden in the future
sounds reasonable.
I would say it another way: rspackChunkName
is the feature, webpackChunkName
is the compatibility layer with webpack... for example, this has been done for HtmlRspackPlugin
And by the way, the purpose of this updated regex is not (only) to introduce rspackChunkName: actually, I started looking at it to be able to create subfolders in chunkNames and use _
or -
character...
started looking at it to be able to create subfolders in chunkNames and use _ or - character...
I will re-create an issue for this. Thanks for your feedback.
What problem does this feature solve?
Rspack has supported the same feature
webpackChunkName
that Webpack has in https://github.com/web-infra-dev/rspack/pull/2686.AKA, Rspack has supported using
import(/* webpackChunkName: "d" */ "./d")
to specify the name of chunks.I hope Rspack could also support using
import(/* rspackChunkName: "d" */ "./d")
to specify the name.Guidance
You should improve the regexp in
https://github.com/web-infra-dev/rspack/blob/99bec3fec54dbea969c157a8236938235ad1b8c2/crates/rspack_plugin_javascript/src/visitors/dependency/scanner.rs#L101-L103
https://jex.im/regulex should be very helpful for writing the regexp.
Well, you should also change the function name to
try_extract_chunk_name_from_magical_comment
in :)https://github.com/web-infra-dev/rspack/blob/99bec3fec54dbea969c157a8236938235ad1b8c2/crates/rspack_plugin_javascript/src/visitors/dependency/scanner.rs#L98
What does the proposed API of configuration look like?
.