Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

proposal: reload and unload a dynamic module #81

@Fenzland

Description

@Fenzland

Background

If we want to build a real time develop system. When you change your code, and fire the event or hook, the browser reload the module automatically. Now we can use the module system of Webpack, and it works well. But with ESModules, there is a big problem, a module will never be reloaded or unloaded. The best solution by now, is import the module dynamically, and when it changes, add a ?v=timestamp to load the module again. But by this, the old module still never unloaded, it cause memory leak.

Proposal

Add ways to reload and unload a dynamic module.
When we reload a module during it loading, just return a new promise with the loading value, but not send a new request.
When we unload a module, it will not be removed immediately, but only remove from module list, and the module object will be collected by GC like a normal object.

Questions

Only can reload or unload dynamic module? or can dynamically upload static modules?

Syntax suggestion

import('./dynamic-module.js');
import.reload('./dynamic-module.js'); // returns the same as previous
import.unload('./dynamic-module.js'); // returns Promise<Boolean> or maybe Promise<undefined>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions