Unverified Commit cb8fdc6d authored by Oskar Grunning's avatar Oskar Grunning Committed by GitHub

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 https://github.com/vercel/next.js/issues/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`
parent 29f20d30
...@@ -233,13 +233,23 @@ module.exports = { ...@@ -233,13 +233,23 @@ module.exports = {
// The format is defined via string where variable parts are enclosed in square brackets []. // The format is defined via string where variable parts are enclosed in square brackets [].
// For example labelFormat: "my-classname--[local]", where [local] will be replaced with the name of the variable the result is assigned to. // For example labelFormat: "my-classname--[local]", where [local] will be replaced with the name of the variable the result is assigned to.
labelFormat?: string, labelFormat?: string,
// default is undefined.
// This option allows you to tell the compiler what imports it should
// look at to determine what it should transform so if you re-export
// Emotion's exports, you can still use transforms.
importMap?: {
[packageName: string]: {
[exportName: string]: {
canonicalImport?: [string, string],
styledBaseImport?: [string, string],
}
}
},
}, },
}, },
} }
``` ```
Only `importMap` in `@emotion/babel-plugin` is not supported for now.
### Minification ### Minification
Next.js' swc compiler is used for minification by default since v13. This is 7x faster than Terser. Next.js' swc compiler is used for minification by default since v13. This is 7x faster than Terser.
......
...@@ -165,6 +165,7 @@ function getEmotionOptions(nextConfig, development) { ...@@ -165,6 +165,7 @@ function getEmotionOptions(nextConfig, development) {
return { return {
enabled: true, enabled: true,
autoLabel, autoLabel,
importMap: nextConfig?.compiler?.emotion?.importMap,
labelFormat: nextConfig?.compiler?.emotion?.labelFormat, labelFormat: nextConfig?.compiler?.emotion?.labelFormat,
sourcemap: development sourcemap: development
? nextConfig?.compiler?.emotion?.sourceMap ?? true ? nextConfig?.compiler?.emotion?.sourceMap ?? true
......
...@@ -52,6 +52,9 @@ const configSchema = { ...@@ -52,6 +52,9 @@ const configSchema = {
type: 'string', type: 'string',
minLength: 1, minLength: 1,
}, },
importMap: {
type: 'object',
},
}, },
}, },
] as any, ] as any,
......
...@@ -491,6 +491,14 @@ export interface NextConfig extends Record<string, any> { ...@@ -491,6 +491,14 @@ export interface NextConfig extends Record<string, any> {
sourceMap?: boolean sourceMap?: boolean
autoLabel?: 'dev-only' | 'always' | 'never' autoLabel?: 'dev-only' | 'always' | 'never'
labelFormat?: string labelFormat?: string
importMap?: {
[importName: string]: {
[exportName: string]: {
canonicalImport?: [string, string]
styledBaseImport?: [string, string]
}
}
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment