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

Feature/custom prefix option #232

Merged
merged 3 commits into from
Dec 6, 2024
Merged
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
5 changes: 5 additions & 0 deletions .changeset/gold-rocks-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"next-yak": minor
---

allow to define a prefix for generated css names like variables
2 changes: 1 addition & 1 deletion .changeset/silver-hairs-clean.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"yak-swc": minor
---

allow to define the prefix for generated names
allow to define a prefix for generated css names like variables
16 changes: 14 additions & 2 deletions packages/next-yak/withYak/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ const { resolve } = createRequire(currentDir + "/index.js");

export type YakConfigOptions = {
contextPath?: string;
/**
* Optional prefix for generated CSS identifiers.
* This can be used to ensure unique class names across different applications
* or to add organization-specific prefixes.
*/
prefix?: string;
experiments?: {
debug?:
| boolean
Expand All @@ -32,7 +38,11 @@ const addYak = (yakOptions: YakConfigOptions, nextConfig: NextConfig) => {
nextConfig.experimental.swcPlugins ||= [];
nextConfig.experimental.swcPlugins.push([
resolve("yak-swc"),
{ devMode: process.env.NODE_ENV !== "production", basePath: currentDir },
{
devMode: process.env.NODE_ENV !== "production",
basePath: currentDir,
prefix: yakOptions.prefix,
},
]);

nextConfig.webpack = (webpackConfig, options) => {
Expand Down Expand Up @@ -104,7 +114,9 @@ function resolveYakContext(contextPath: string | undefined, cwd: string) {
* // your next config here
* };
* const yakConfig = {
* // your yak config
* // Optional prefix for generated CSS identifiers
* prefix: "my-app",
* // Other yak config options...
* };
* module.exports = withYak(yakConfig, nextConfig);
* ```
Expand Down
Loading