Skip to content

Commit

Permalink
fix: enable emotion import map (#42750)
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
sQVe committed Nov 10, 2022
1 parent 29f20d3 commit cb8fdc6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
14 changes: 12 additions & 2 deletions docs/advanced-features/compiler.md
Expand Up @@ -233,13 +233,23 @@ module.exports = {
// 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.
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

Next.js' swc compiler is used for minification by default since v13. This is 7x faster than Terser.
Expand Down
1 change: 1 addition & 0 deletions packages/next/build/swc/options.js
Expand Up @@ -165,6 +165,7 @@ function getEmotionOptions(nextConfig, development) {
return {
enabled: true,
autoLabel,
importMap: nextConfig?.compiler?.emotion?.importMap,
labelFormat: nextConfig?.compiler?.emotion?.labelFormat,
sourcemap: development
? nextConfig?.compiler?.emotion?.sourceMap ?? true
Expand Down
3 changes: 3 additions & 0 deletions packages/next/server/config-schema.ts
Expand Up @@ -52,6 +52,9 @@ const configSchema = {
type: 'string',
minLength: 1,
},
importMap: {
type: 'object',
},
},
},
] as any,
Expand Down
8 changes: 8 additions & 0 deletions packages/next/server/config-shared.ts
Expand Up @@ -491,6 +491,14 @@ export interface NextConfig extends Record<string, any> {
sourceMap?: boolean
autoLabel?: 'dev-only' | 'always' | 'never'
labelFormat?: string
importMap?: {
[importName: string]: {
[exportName: string]: {
canonicalImport?: [string, string]
styledBaseImport?: [string, string]
}
}
}
}
}

Expand Down

0 comments on commit cb8fdc6

Please sign in to comment.