rspack icon indicating copy to clipboard operation
rspack copied to clipboard

[Feature Request]: Dynamic entry

Open OrangeXC opened this issue 1 year ago • 10 comments
trafficstars

What problem does this feature solve?

We plan to migrate from webpack. The existing function is to implement access-time building through dynamic entry (that is, the build task is triggered when the user accesses the local URL). The entry configuration code is as follows:

// The file record entry changes
const entryDynamicFile = `${process.env.BUILD_ENTRY_DYNAMIC}-${type}.json`
const ENTRY_DYNAMIC = 'entry-dynamic'

module.exports = {
  entry: () => {
    // Return object include all entries key value
    const entries = getEntry()
    const list = JSON.parse(readFileSync(entryDynamicFile))
    const dynamicEntries = {}
    list.forEach((name) => { dynamicEntries[name] = path.join(process.cwd(), entries[name]) })
    dynamicEntries[ENTRY_DYNAMIC] = entryDynamicFile
    return dynamicEntries
  }
}

We find the corresponding entry based on the URL visited by the user. If the current entry history has not been constructed, a loading page will be returned. We use this feature to dynamically change the entry. When the construction is completed, refresh the entry page again to display the true content of the entry.

What does the proposed API of configuration look like?

The Webpack Document: https://webpack.js.org/configuration/entry-context/#dynamic-entry

OrangeXC avatar Jan 20 '24 09:01 OrangeXC

By now, you can try to export a function type option as a workaround.

h-a-n-a avatar Jan 22 '24 08:01 h-a-n-a

By now, you can try to export a function type option as a workaround.

I don’t understand. Currently rspack does not support function type entries. Can you provide a simple code example?

OrangeXC avatar Jan 23 '24 03:01 OrangeXC

Maybe @h-a-n-a means, you can export function type rspack config https://www.rspack.dev/config.html#exporting-a-configuration-function

faga295 avatar Jan 25 '24 07:01 faga295

Maybe @h-a-n-a means, you can export function type rspack config https://www.rspack.dev/config.html#exporting-a-configuration-function

That's exactly that I mean. Sorry for making it confusing.

h-a-n-a avatar Jan 25 '24 07:01 h-a-n-a

This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

stale[bot] avatar Mar 25 '24 07:03 stale[bot]

bump

childrentime avatar Apr 28 '24 08:04 childrentime

https://github.com/childrentime/rspack-EntryOptionPlugin-diff-with-webpack

childrentime avatar Apr 28 '24 08:04 childrentime

I am using the EntryOptionPlugin to add a route when a page route is accessed. However, I found that rspack's EntryOptionPlugin does not allow a function to be used as an entry. This is clearly inconsistent with the plugins in webpack.

childrentime avatar Apr 28 '24 08:04 childrentime

https://github.com/webpack/webpack/blob/4b4ca3bb53f36a5b8fc6bc1bd976ed7af161bd80/lib/EntryOptionPlugin.js#L31-L35

childrentime avatar Apr 28 '24 08:04 childrentime

https://github.com/web-infra-dev/rspack/blob/main/packages/rspack/src/lib/EntryOptionPlugin.ts#L28-L31 Just saw that it's not supported yet. 😭

childrentime avatar Apr 28 '24 08:04 childrentime

Close with https://github.com/web-infra-dev/rspack/pull/6393

SyMind avatar Jun 13 '24 05:06 SyMind