Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ body:
[plugin-jsx-remove-attributes](https://github.com/rolldown/plugins/tree/main/packages/jsx-remove-attributes)
- label: |-
[plugin-styled-jsx](https://github.com/rolldown/plugins/tree/main/packages/styled-jsx)
- label: |-
[plugin-transform-imports](https://github.com/rolldown/plugins/tree/main/packages/transform-imports)
- type: textarea
id: bug-description
attributes:
Expand Down
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ body:
[plugin-jsx-remove-attributes](https://github.com/rolldown/plugins/tree/main/packages/jsx-remove-attributes)
- label: |-
[plugin-styled-jsx](https://github.com/rolldown/plugins/tree/main/packages/styled-jsx)
- label: |-
[plugin-transform-imports](https://github.com/rolldown/plugins/tree/main/packages/transform-imports)
- type: textarea
id: feature-description
attributes:
Expand Down
2 changes: 2 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
- '/- \[x\] \[plugin-jsx-remove-attributes\]/i'
'plugin: styled-jsx':
- '/- \[x\] \[plugin-styled-jsx\]/i'
'plugin: transform-imports':
- '/- \[x\] \[plugin-transform-imports\]/i'
4 changes: 4 additions & 0 deletions .github/pr-labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
- changed-files:
- any-glob-to-any-file: 'packages/styled-jsx/**'

'plugin: transform-imports':
- changed-files:
- any-glob-to-any-file: 'packages/transform-imports/**'

'package: oxc-unshadowed-visitor':
- changed-files:
- any-glob-to-any-file: 'packages/oxc-unshadowed-visitor/**'
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Official Rolldown plugins
- [`@rolldown/plugin-emotion`](https://github.com/rolldown/plugins/tree/main/packages/emotion) ([![NPM version][badge-npm-version-emotion]][url-npm-emotion]): minification and optimization of Emotion styles
- [`@rolldown/plugin-jsx-remove-attributes`](https://github.com/rolldown/plugins/tree/main/packages/jsx-remove-attributes) ([![NPM version][badge-npm-version-jsx-remove-attributes]][url-npm-jsx-remove-attributes]): remove JSX attributes (e.g. data-testid)
- [`@rolldown/plugin-styled-jsx`](https://github.com/rolldown/plugins/tree/main/packages/styled-jsx) ([![NPM version][badge-npm-version-styled-jsx]][url-npm-styled-jsx]): Rolldown plugin for styled-jsx CSS scoping
- [`@rolldown/plugin-transform-imports`](https://github.com/rolldown/plugins/tree/main/packages/transform-imports) ([![NPM version][badge-npm-version-transform-imports]][url-npm-transform-imports]): transform imports/exports to barrel files

### Other Packages

Expand All @@ -38,9 +39,11 @@ Official Rolldown plugins
[badge-npm-version-emotion]: https://img.shields.io/npm/v/@rolldown/plugin-emotion?color=brightgreen
[badge-npm-version-jsx-remove-attributes]: https://img.shields.io/npm/v/@rolldown/plugin-jsx-remove-attributes?color=brightgreen
[badge-npm-version-styled-jsx]: https://img.shields.io/npm/v/@rolldown/plugin-styled-jsx?color=brightgreen
[badge-npm-version-transform-imports]: https://img.shields.io/npm/v/@rolldown/plugin-transform-imports?color=brightgreen
[badge-npm-version-oxc-unshadowed-visitor]: https://img.shields.io/npm/v/oxc-unshadowed-visitor?color=brightgreen
[url-npm-babel]: https://npmx.dev/package/@rolldown/plugin-babel
[url-npm-emotion]: https://npmx.dev/package/@rolldown/plugin-emotion
[url-npm-jsx-remove-attributes]: https://npmx.dev/package/@rolldown/plugin-jsx-remove-attributes
[url-npm-styled-jsx]: https://npmx.dev/package/@rolldown/plugin-styled-jsx
[url-npm-transform-imports]: https://npmx.dev/package/@rolldown/plugin-transform-imports
[url-npm-oxc-unshadowed-visitor]: https://npmx.dev/package/oxc-unshadowed-visitor
12 changes: 12 additions & 0 deletions examples/transform-imports/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Transform Imports Example</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
14 changes: 14 additions & 0 deletions examples/transform-imports/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@rolldown/example-transform-imports",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"@rolldown/plugin-transform-imports": "workspace:*",
"vite": "^8.0.7"
}
}
19 changes: 19 additions & 0 deletions examples/transform-imports/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @ts-expect-error not typed
import { Button, Card, Modal } from 'mock-lib'

const app = document.getElementById('app')!

const heading = document.createElement('h1')
heading.textContent = 'Transform Imports Example'
heading.className = 'app-title'
app.appendChild(heading)

const description = document.createElement('p')
description.textContent =
'These components are imported via barrel import, transformed to individual imports by the plugin.'
description.className = 'app-description'
app.appendChild(description)

app.appendChild(Button())
app.appendChild(Card())
app.appendChild(Modal())
6 changes: 6 additions & 0 deletions examples/transform-imports/src/mock-lib/button.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default function Button() {
const el = document.createElement('button')
el.textContent = 'Button'
el.className = 'mock-button'
return el
}
6 changes: 6 additions & 0 deletions examples/transform-imports/src/mock-lib/card.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default function Card() {
const el = document.createElement('div')
el.textContent = 'Card'
el.className = 'mock-card'
return el
}
5 changes: 5 additions & 0 deletions examples/transform-imports/src/mock-lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export { default as Button } from './button.js'
export { default as Input } from './input.js'
export { default as Select } from './select.js'
export { default as Modal } from './modal.js'
export { default as Card } from './card.js'
6 changes: 6 additions & 0 deletions examples/transform-imports/src/mock-lib/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default function Input() {
const el = document.createElement('input')
el.placeholder = 'Input'
el.className = 'mock-input'
return el
}
6 changes: 6 additions & 0 deletions examples/transform-imports/src/mock-lib/modal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default function Modal() {
const el = document.createElement('div')
el.textContent = 'Modal'
el.className = 'mock-modal'
return el
}
8 changes: 8 additions & 0 deletions examples/transform-imports/src/mock-lib/select.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function Select() {
const el = document.createElement('select')
el.className = 'mock-select'
const option = document.createElement('option')
option.textContent = 'Select'
el.appendChild(option)
return el
}
20 changes: 20 additions & 0 deletions examples/transform-imports/transform-imports.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { expect, test } from 'vitest'
import { page } from '~utils'

test('should render button component', async () => {
const el = page.locator('.mock-button')
const text = await el.textContent()
expect(text).toBe('Button')
})

test('should render card component', async () => {
const el = page.locator('.mock-card')
const text = await el.textContent()
expect(text).toBe('Card')
})

test('should render modal component', async () => {
const el = page.locator('.mock-modal')
const text = await el.textContent()
expect(text).toBe('Modal')
})
20 changes: 20 additions & 0 deletions examples/transform-imports/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { defineConfig } from 'vite'
import transformImports from '@rolldown/plugin-transform-imports'
import path from 'node:path'

export default defineConfig({
plugins: [
transformImports({
modules: {
'mock-lib': {
transform: 'mock-lib/{{kebabCase member}}',
},
},
}),
],
resolve: {
alias: {
'mock-lib': path.resolve(import.meta.dirname, './src/mock-lib'),
},
},
})
1 change: 1 addition & 0 deletions internal-packages/swc-output-gen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@swc/plugin-emotion": "^14.8.0",
"@swc/plugin-react-remove-properties": "^12.8.0",
"@swc/plugin-styled-jsx": "^13.8.0",
"@swc/plugin-transform-imports": "^12.8.0",
"rolldown": "^1.0.0-rc.13",
"tinyglobby": "^0.2.15"
}
Expand Down
11 changes: 11 additions & 0 deletions internal-packages/swc-output-gen/src/plugin-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ export const pluginRegistry: Record<string, PluginConfig> = {
return [['@swc/plugin-styled-jsx', swcConfig]]
},
},
'transform-imports': {
packages: ['@swc/plugin-transform-imports'],
mapOptions: (config) => [['@swc/plugin-transform-imports', config]],
shouldSkip: (config) => {
// SWC plugin only supports camelCase and kebabCase helpers
// Our ported plugin also supports snakeCase, lowerCase, upperCase
const unsupportedHelpers = ['snakeCase', 'lowerCase', 'upperCase']
const configStr = JSON.stringify(config)
return unsupportedHelpers.some((helper) => configStr.includes(helper))
},
},
}

/** Get list of all supported plugin names */
Expand Down
Empty file.
Loading
Loading