Skip to content

Allow using a function in transform for the SWC modularized imports #36055

@makezi

Description

@makezi

Describe the feature you'd like to request

From #34969, it would be great if it were possible to allow the transformer to allow functions (similar to that of function transformer from babel-plugin-transform-imports).

Right now, I'm trying to import a react component library that uses hyphen-case as its naming convention and currently there is no way of doing so - there's only helpers for uppercase, lowercase and camel case. An example import:

// works
import { TextLink } from '@our-design-system/dist/components/text-link'; 

// Will fail as {{member}} will result in '@our-design system/dist/components/TextLink'
import { TextLink } from '@our-design-system/components'; 

Describe the solution you'd like

Either one of two solutions:

  1. Provide a hypenCase helper to the handlebars transform function similar to that of the other provided helpersm i.e. @our-design-system/dist/components/{{ hypenCase member}}. Although this doesn't give us enough power of the transformations compared to option 2.
  2. Allow transform to accept a function similar to that from babel-plugin-transform-imports)
modularizeImports: {
  '@our-design-system/components': {
    transform: (importName, matches) => `@our-design-system/dist/components/${hyphenCase(importName)}`
  }
}

Describe alternatives you've considered

The only other solution is to just defer back to babel.config.js and use babel plugins.

Metadata

Metadata

Assignees

No one assigned

    Labels

    SWCRelated to minification/transpilation in Next.js.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions