Skip to content

Commit cb8fdc6

Browse files
authored
fix: enable emotion import map (#42750)
This PR aims to add support for the `importMap` option for `emotion`. It's already supported by `swc_emotion`. Fixes #41646. ## Feature - [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [x] Related issues linked using `fixes #number` - [ ] Integration tests added - [x] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see `contributing.md`
1 parent 29f20d3 commit cb8fdc6

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

docs/advanced-features/compiler.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,23 @@ module.exports = {
233233
// The format is defined via string where variable parts are enclosed in square brackets [].
234234
// For example labelFormat: "my-classname--[local]", where [local] will be replaced with the name of the variable the result is assigned to.
235235
labelFormat?: string,
236+
// default is undefined.
237+
// This option allows you to tell the compiler what imports it should
238+
// look at to determine what it should transform so if you re-export
239+
// Emotion's exports, you can still use transforms.
240+
importMap?: {
241+
[packageName: string]: {
242+
[exportName: string]: {
243+
canonicalImport?: [string, string],
244+
styledBaseImport?: [string, string],
245+
}
246+
}
247+
},
236248
},
237249
},
238250
}
239251
```
240252

241-
Only `importMap` in `@emotion/babel-plugin` is not supported for now.
242-
243253
### Minification
244254

245255
Next.js' swc compiler is used for minification by default since v13. This is 7x faster than Terser.

packages/next/build/swc/options.js

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ function getEmotionOptions(nextConfig, development) {
165165
return {
166166
enabled: true,
167167
autoLabel,
168+
importMap: nextConfig?.compiler?.emotion?.importMap,
168169
labelFormat: nextConfig?.compiler?.emotion?.labelFormat,
169170
sourcemap: development
170171
? nextConfig?.compiler?.emotion?.sourceMap ?? true

packages/next/server/config-schema.ts

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ const configSchema = {
5252
type: 'string',
5353
minLength: 1,
5454
},
55+
importMap: {
56+
type: 'object',
57+
},
5558
},
5659
},
5760
] as any,

packages/next/server/config-shared.ts

+8
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,14 @@ export interface NextConfig extends Record<string, any> {
491491
sourceMap?: boolean
492492
autoLabel?: 'dev-only' | 'always' | 'never'
493493
labelFormat?: string
494+
importMap?: {
495+
[importName: string]: {
496+
[exportName: string]: {
497+
canonicalImport?: [string, string]
498+
styledBaseImport?: [string, string]
499+
}
500+
}
501+
}
494502
}
495503
}
496504

0 commit comments

Comments
 (0)