swc-project / swc

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

Ability to use a virtualised filesystem #9671

Closed asos-tomp closed 3 weeks ago

asos-tomp commented 3 weeks ago

Describe the feature

Work off virtualised filesystems. e.g. In memory.

Babel plugin or link to the feature description

https://github.com/sysgears/webpack-virtual-modules/issues/169

Additional context

I appreciate the purpose of SWC is speed/efficiency, and this perhaps may only be gleaned by focussing on raw metal, but wondered if there was any possibility to work from a virtualised filesystem, e.g. memfs?

I have a plugin that works fine with NextJs (WebPack + Babel) but fails with WebPack + SWC, since the abstract compiler.inputFileSystem concept doesn't appear to be fully supported.

kdy1 commented 3 weeks ago

Maybe we may support one for Wasm, but your plugin is for webpack, a bundler, not babel. Also, I read the thread you linked but swc-loader does not read file directly from the file system. We just use source code provided by webpack.

larixer commented 3 weeks ago

@kdy1 Next.js does not use swc-loader by default, at least not in the latest version. Instead Next.js ships its own integration with SWC, @next/swc which reads files directly from the file system. https://github.com/vercel/next.js/blob/ca559a5281ff2e2f345cc45e4d05a82e7ba83c9f/crates/napi/src/transform.rs#L118-L120

The issue should be opened against Next.js repo, I think.

asos-tomp commented 3 weeks ago

Thanks @larixer - much appreciated for clarifying for me. Will raise an issue against Next.

larixer commented 3 weeks ago

Addition, seems direct file reading into @next/swc was added via this PR: https://github.com/vercel/next.js/pull/31682 Looks like next-swc-loader is the last loader and because of this file reading is "accelerated" by delegating it to Rust code.

asos-tomp commented 3 weeks ago

See: https://github.com/vercel/next.js/discussions/71714 raised earlier