Support ESM import/export in config files.

One of the things I’ve noticed while writing ESM code is that I reach for it all the time, even when writing webpack.config.js files. It would be rad if webpack 4 used something like @std/esm behind the scenes to load its config files. In addition to CJS, this would enable support for ESM import, export, dynamic import, and import.meta with config files across Node versions. Thoughts?

Author: Fantashit

5 thoughts on “Support ESM import/export in config files.

  1. Ideally it would work with .js without the need to register a handler with js-interpret.
    It should probably also “just work” with .mjs, because that’s where Node is likely going, without the need to register a handler as well.

    Update:
    Clarified per @bmeck‘s comment.

  2. For these things, the tool can always just make it a standard that can be shared across environments and remove the burdens.

    Standards are great. User-land is also great because it has the freedom to try things out, like JSON5 or ESM in configs, giving wins to devs today while influencing the standards of tomorrow independently and organically.

  3. As a compromise we can add --config-register to the CLI which is similar to -r in node.

    webpack --config-register @std/esm would allow to use import/export in configuration. This would also be great for babel users which can choose to use ES201X in webpack.config.js with
    --config-register babel-register

Comments are closed.