swc-project / swc

Rust-based platform for the Web
https://swc.rs
Apache License 2.0
30.99k stars 1.21k forks source link

Support `package.exports` in NodeModulesResolver #6092

Open hanayashiki opened 1 year ago

hanayashiki commented 1 year ago

Describe the feature

Right now subpath exports is around there for a while, and a number of packages are using them to handle conditional cjs/esm exports, so that both platforms are supported.

It seems SWC doesn't support this feature in NodeModulesResolver yet.

Source

#[derive(Deserialize)]
struct PackageJson {
    #[serde(default)]
    main: Option<String>,
    #[serde(default)]
    browser: Option<Browser>,
    #[serde(default)]
    module: Option<String>,
}

In the definition of PackageJson, there are no definitions of exports, so I assume this feature is not quite there yet.

I wish this could be handled in the future.

Babel plugin or link to the feature description

No response

Additional context

No response

mohamedmansour commented 1 year ago

Many packages started supporting package exports because that is one way to support pure ESModules. Here is an example repo that showcases that it passes esbuild/webpack but fails with swc.

https://github.com/mohamedmansour/web-components-perf

kdy1 commented 1 year ago

@mohamedmansour What are you trying to do? Are you trying to use swcpack? I don't think it's a good idea.

mohamedmansour commented 1 year ago

@mohamedmansour What are you trying to do? Are you trying to use swcpack? I don't think it's a good idea.

I was following this https://swc.rs/docs/usage/bundling, I wanted to replace webpack with either esbuild or swc.

kdy1 commented 1 year ago

I added some more context about the status of swcpack to https://swc.rs/docs/usage/bundling