swc-project / swc

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

Ability to modify import extensions, like ".scss" to ".css" #9614

Open wermanoid opened 1 month ago

wermanoid commented 1 month ago

Describe the feature

I'm trying to migrate away from @babel to swc, and stuck with this one issue. We're using .scss files for development and processing those into css during builds.

In case of @babel - it is possible to setup transformation, that will change sass/less into css. And there is ability to work with import extensions in general.

Only thing that I've found for SWC was this - https://github.com/swc-project/plugins/issues/47 and, unfortunately, this behavior was fixed and not available any more.

Can you add ability to change imports during builds? You know, this is pretty weird idea to go away from babel, so later I would have to use swc + babel to finalize compilation.

Or there is already something to implement similar logic (except use babel to process compiled code)?

Babel plugin or link to the feature description

transform-rename-import

Additional context

No response

dr2009 commented 3 days ago

just add handleDefaultImport: true

[
  '@swc/plugin-transform-imports',
  {
    '^(.*?)(\\.scss)$': {
      handleDefaultImport: true,
      transform: '{{matches.[1]}}.css',
    },
  },
],