Unverified Commit de7aa2d6 authored by John Daly's avatar John Daly Committed by GitHub

Support postcss.config.cjs (#38486)

* Adding support for finding configuration files that end with .config.cjs

* Adding another test

* Remove .only
parent 35a32438
...@@ -30,13 +30,14 @@ export async function findConfig<T>( ...@@ -30,13 +30,14 @@ export async function findConfig<T>(
`${key}.config.json`, `${key}.config.json`,
`.${key}rc.js`, `.${key}rc.js`,
`${key}.config.js`, `${key}.config.js`,
`${key}.config.cjs`,
], ],
{ {
cwd: directory, cwd: directory,
} }
) )
if (filePath) { if (filePath) {
if (filePath.endsWith('.js')) { if (filePath.endsWith('.js') || filePath.endsWith('.cjs')) {
return require(filePath) return require(filePath)
} }
......
import 'tailwindcss/tailwind.css'
function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
export default MyApp
export default function Home() {
return (
<div className="flex flex-col items-center justify-center min-h-screen py-2">
<main className="flex flex-col items-center justify-center w-full flex-1 px-20 text-center">
<h1 className="text-blue-600 text-6xl font-bold">
Welcome to{' '}
<a className="text-blue-600" href="https://nextjs.org" id="test-link">
Next.js!
</a>
</h1>
<p className="mt-3 text-2xl">
Get started by editing{' '}
<code className="p-3 font-mono text-lg bg-gray-100 rounded-md">
pages/index.js
</code>
</p>
<div className="flex flex-wrap items-center justify-around max-w-4xl mt-6 sm:w-full">
<a
href="https://nextjs.org/docs"
className="p-6 mt-6 text-left border w-96 rounded-xl hover:text-blue-600 focus:text-blue-600"
>
<h3 className="text-2xl font-bold">Documentation &rarr;</h3>
<p className="mt-4 text-xl">
Find in-depth information about Next.js features and API.
</p>
</a>
<a
href="https://nextjs.org/learn"
className="p-6 mt-6 text-left border w-96 rounded-xl hover:text-blue-600 focus:text-blue-600"
>
<h3 className="text-2xl font-bold">Learn &rarr;</h3>
<p className="mt-4 text-xl">
Learn about Next.js in an interactive course with quizzes!
</p>
</a>
<a
href="https://github.com/vercel/next.js/tree/canary/examples"
className="p-6 mt-6 text-left border w-96 rounded-xl hover:text-blue-600 focus:text-blue-600"
>
<h3 className="text-2xl font-bold">Examples &rarr;</h3>
<p className="mt-4 text-xl">
Discover and deploy boilerplate example Next.js projects.
</p>
</a>
<a
href="https://vercel.com/import?filter=next.js&utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
className="p-6 mt-6 text-left border w-96 rounded-xl hover:text-blue-600 focus:text-blue-600"
>
<h3 className="text-2xl font-bold">Deploy &rarr;</h3>
<p className="mt-4 text-xl">
Instantly deploy your Next.js site to a public URL with Vercel.
</p>
</a>
</div>
</main>
</div>
)
}
// If you want to use other PostCSS plugins, see the following:
// https://tailwindcss.com/docs/using-with-preprocessors
module.exports = {
plugins: {
tailwindcss: {},
},
}
module.exports = {
mode: 'jit',
purge: ['./pages/**/*.{js,ts,jsx,tsx}', './components/**/*.{js,ts,jsx,tsx}'],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
}
import { createNext, FileRef } from 'e2e-utils'
import { join } from 'path'
import { NextInstance } from 'test/lib/next-modes/base'
import webdriver from 'next-webdriver'
describe('postcss-config-cjs', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: {
'postcss.config.cjs': new FileRef(
join(__dirname, 'app/postcss.config.cjs')
),
'tailwind.config.cjs': new FileRef(
join(__dirname, 'app/tailwind.config.cjs')
),
pages: new FileRef(join(__dirname, 'app/pages')),
},
dependencies: {
tailwindcss: '2.2.19',
postcss: '8.3.5',
},
})
})
afterAll(() => next.destroy())
it('works with postcss.config.cjs files', async () => {
let browser
try {
browser = await webdriver(next.appPort, '/')
const text = await browser.elementByCss('.text-6xl').text()
expect(text).toMatch(/Welcome to/)
const cssBlue = await browser
.elementByCss('#test-link')
.getComputedCss('color')
expect(cssBlue).toBe('rgb(37, 99, 235)')
} finally {
if (browser) {
await browser.close()
}
}
})
})
...@@ -28,6 +28,11 @@ describe('find config', () => { ...@@ -28,6 +28,11 @@ describe('find config', () => {
expect(config).toEqual({ foo: 'bar' }) expect(config).toEqual({ foo: 'bar' })
}) })
it('should resolve .config.cjs', async () => {
const config = await findConfig(join(fixtureDir, 'config-long-cjs'), 'test')
expect(config).toEqual({ foo: 'bar' })
})
it('should resolve package.json', async () => { it('should resolve package.json', async () => {
const config = await findConfig( const config = await findConfig(
join(fixtureDir, 'config-package-json'), join(fixtureDir, 'config-package-json'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment