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

How can I custom a theme with NX+Next.js? #83

Open
JenniferGoijman opened this issue May 13, 2024 · 4 comments · May be fixed by #114
Open

How can I custom a theme with NX+Next.js? #83

JenniferGoijman opened this issue May 13, 2024 · 4 comments · May be fixed by #114
Assignees
Labels
enhancement This is not a bug, nor a new feature support: docs-feedback Feedback from documentation page support: question Community support but can be turned into an improvement

Comments

@JenniferGoijman
Copy link

JenniferGoijman commented May 13, 2024

Related page

https://github.com/mui/pigment-css?tab=readme-ov-file#start-with-nextjs

Kind of issue

Missing information

Issue description

This is my next.config.jsfile that I have configured PigmentCSS in a Nx+Next.js repo:

//@ts-check

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { composePlugins, withNx } = require('@nx/next');
const { withPigment } = require('@pigment-css/nextjs-plugin');

/**
 * @type {import('@nx/next/plugins/with-nx').WithNxOptions}
 **/
const nextConfig = {
  nx: {
    // Set this to true if you would like to to use SVGR
    // See: https://github.com/gregberge/svgr
    svgr: false,
  },
};

const plugins = [
  // Add more Next.js plugins to this list if needed.
  withNx,
  withPigment
];

module.exports = composePlugins(...plugins)(nextConfig);

How can I custom a theme with NX+Next.js?

Context

@pigment-css/react: 0.0.11
next: 14.0.4
react: 18.2.0
react-dom: 18.2.0
@nx/next: 18.0.2
@pigment-css/nextjs-plugin: 0.0.11
nx: 18.0.2

Search keywords: NX, Next.js

@JenniferGoijman JenniferGoijman added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: docs-feedback Feedback from documentation page labels May 13, 2024
@zannager zannager added the support: question Community support but can be turned into an improvement label May 27, 2024
@brijeshb42
Copy link
Contributor

brijeshb42 commented May 30, 2024

This requires a change in the api of withPigment to take in it's config from the nextConfig object itself instead of taking it as a 2nd argument.
This will be a breaking change but makes sense if majority of other plugins are already following this approach.

@brijeshb42 brijeshb42 added enhancement This is not a bug, nor a new feature and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels May 30, 2024
brijeshb42 added a commit to brijeshb42/pigment-css that referenced this issue May 30, 2024
through `pigment` key from the nextConfig object itself instead of as a
2nd argument to the call. This is a standard approach followed by other
nextjs plugins

Fixes: mui#83
@brijeshb42 brijeshb42 linked a pull request May 30, 2024 that will close this issue
1 task
brijeshb42 added a commit to brijeshb42/pigment-css that referenced this issue Jun 17, 2024
through `pigment` key from the nextConfig object itself instead of as a
2nd argument to the call. This is a standard approach followed by other
nextjs plugins

Fixes: mui#83
brijeshb42 added a commit to brijeshb42/pigment-css that referenced this issue Jun 17, 2024
through `pigment` key from the nextConfig object itself instead of as a
2nd argument to the call. This is a standard approach followed by other
nextjs plugins

Fixes: mui#83
brijeshb42 added a commit to brijeshb42/pigment-css that referenced this issue Jun 21, 2024
through `pigment` key from the nextConfig object itself instead of as a
2nd argument to the call. This is a standard approach followed by other
nextjs plugins

Fixes: mui#83
@omerman
Copy link

omerman commented Aug 31, 2024

Getting this error on a setup with nx monorepo.
image

//@ts-check

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { createTheme } = require('@mui/material');
const { composePlugins, withNx } = require('@nx/next');
const { withPigment } = require('@pigment-css/nextjs-plugin');
require('../../core/src/next/utils/prepareEnv');

/**
 * @type {import('@nx/next/plugins/with-nx').WithNxOptions}
 **/
const nextConfig = {
  nx: {
    // Set this to true if you would like to use SVGR
    // See: https://github.com/gregberge/svgr
    svgr: false,
  },

  eslint: {
    ignoreDuringBuilds: false,
  },
  basePath: process.env['NEXT_PUBLIC_BASE_PATH'] || undefined,
  experimental: {
    // optimizePackageImports: ['@mui/material', 'lodash-es', 'react-icons'],
    after: true, // To run long tasks after response is sent to user.
    // ppr: true,
  },
};

const plugins = [
  // Add more Next.js plugins to this list if needed.
  withNx,
  (nextConfig) => {
    return withPigment(nextConfig, {
      theme: createTheme({
        cssVariables: true,
        colorSchemes: { light: true },
        typography: {
          fontFamily: 'var(--font-heebo)',
        },
      }),
      transformLibraries: ['@mui/material'],
    });
  },
];

module.exports = composePlugins(...plugins)(nextConfig);

The above yields an error. And I believe it should work.

@alexanderdavide
Copy link

Based on @omerman's input, the following works. Using extendTheme is essential.

import { extendTheme } from "@mui/material";
import { composePlugins, withNx } from "@nx/next";
import { withPigment as withPigmentNext } from "@pigment-css/nextjs-plugin";

/**
 * @type {import('@nx/next/plugins/with-nx').WithNxOptions}
 **/
const nextConfig = { };

/**
 * @type {import('@nx/next/src/utils/config').NextPlugin}
 */
const withPigment = (nextConfig) => {
  /**
   * @type {import('@pigment-css/nextjs-plugin').PigmentOptions}
   */
  const pigmentConfig = {
    transformLibraries: ["@mui/material"],
    theme: extendTheme({ }),
  };

  return withPigmentNext(nextConfig, pigmentConfig);
};

const plugins = [withNx, withPigment];

export default composePlugins(...plugins)(nextConfig);

@omerman
Copy link

omerman commented Sep 9, 2024

Ill check soon as well 🙏🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is not a bug, nor a new feature support: docs-feedback Feedback from documentation page support: question Community support but can be turned into an improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants