Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enable emotion import map #42750

Merged
merged 2 commits into from Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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