Skip to content

Commit

Permalink
Switch to postcss.config.mjs, add type (#63380)
Browse files Browse the repository at this point in the history
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

-->

### What?

Now that @phanect added support for ESM PostCSS config files in PR
#63109 (original issue #34448), PostCSS can use ESM config by default.

It needs to use an `.mjs` extension by default because `create-next-app`
scaffolds CommonJS apps by default.

This will also work with ESM projects which have added `"type":
"module"` in their `package.json`

### Why?

1. To convert one more file to ESM
2. To use the modern format
3. To follow other similar migrations that have taken place in the
Next.js codebase (eg. `next.config.mjs`)

### How?

- Change file extensions from `.cjs` to `.mjs` (change similar to PR
#58380)
- Change module format from CommonJS to ESM
- Add type for the config, for users who enable `checkJs: true` in
`tsconfig.json`

Co-authored-by: Sam Ko <sam@vercel.com>
  • Loading branch information
karlhorky and samcx committed Mar 18, 2024
1 parent dd7b058 commit 51b878f
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 26 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('postcss-load-config').Config} */
const config = {
plugins: {
tailwindcss: {},
},
};

export default config;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('postcss-load-config').Config} */
const config = {
plugins: {
tailwindcss: {},
},
};

export default config;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('postcss-load-config').Config} */
const config = {
plugins: {
tailwindcss: {},
},
};

export default config;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('postcss-load-config').Config} */
const config = {
plugins: {
tailwindcss: {},
},
};

export default config;
2 changes: 1 addition & 1 deletion packages/create-next-app/templates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const installTemplate = async ({
if (!tailwind)
copySource.push(
mode == "ts" ? "tailwind.config.ts" : "!tailwind.config.js",
"!postcss.config.cjs",
"!postcss.config.mjs",
);

await copy(copySource, root, {
Expand Down
8 changes: 4 additions & 4 deletions test/integration/create-next-app/lib/specification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const projectSpecification: ProjectSpecification = {
'pages/_app.js',
'pages/api/hello.js',
'pages/index.js',
'postcss.config.cjs',
'postcss.config.mjs',
'tailwind.config.js',
],
deps: [],
Expand All @@ -80,7 +80,7 @@ export const projectSpecification: ProjectSpecification = {
'pages/_app.tsx',
'pages/api/hello.ts',
'pages/index.tsx',
'postcss.config.cjs',
'postcss.config.mjs',
'tailwind.config.ts',
'tsconfig.json',
],
Expand Down Expand Up @@ -125,7 +125,7 @@ export const projectSpecification: ProjectSpecification = {
'app/layout.js',
'app/page.js',
'jsconfig.json',
'postcss.config.cjs',
'postcss.config.mjs',
'tailwind.config.js',
],
},
Expand All @@ -143,7 +143,7 @@ export const projectSpecification: ProjectSpecification = {
'app/layout.tsx',
'app/page.tsx',
'next-env.d.ts',
'postcss.config.cjs',
'postcss.config.mjs',
'tailwind.config.ts',
'tsconfig.json',
],
Expand Down
2 changes: 1 addition & 1 deletion test/integration/create-next-app/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const shouldBeTemplateProject = ({
files: getProjectSetting({ template, mode, setting: 'files', srcDir }),
})

// Tailwind templates share the same files (tailwind.config.js, postcss.config.cjs)
// Tailwind templates share the same files (tailwind.config.js, postcss.config.mjs)
if (template !== 'app-tw' && template !== 'default-tw') {
projectFilesShouldNotExist({
cwd,
Expand Down

0 comments on commit 51b878f

Please sign in to comment.