Unverified Commit f4fbb83d authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

allow to provide postcss plugin options as a string (#35173)

fixes https://github.com/vercel/next.js/issues/35117

@balazsorban44 this needs a test case

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
Co-authored-by: 's avatarBalázs Orbán <18369201+balazsorban44@users.noreply.github.com>
parent 3d4f4c69
...@@ -9,7 +9,7 @@ type CssPluginCollection = ...@@ -9,7 +9,7 @@ type CssPluginCollection =
| CssPluginCollection_Array | CssPluginCollection_Array
| CssPluginCollection_Object | CssPluginCollection_Object
type CssPluginShape = [string, object | boolean] type CssPluginShape = [string, object | boolean | string]
const genericErrorText = 'Malformed PostCSS Configuration' const genericErrorText = 'Malformed PostCSS Configuration'
...@@ -62,7 +62,7 @@ const createLazyPostCssPlugin = ( ...@@ -62,7 +62,7 @@ const createLazyPostCssPlugin = (
async function loadPlugin( async function loadPlugin(
dir: string, dir: string,
pluginName: string, pluginName: string,
options: boolean | object options: boolean | object | string
): Promise<import('postcss').AcceptedPlugin | false> { ): Promise<import('postcss').AcceptedPlugin | false> {
if (options === false || isIgnoredPlugin(pluginName)) { if (options === false || isIgnoredPlugin(pluginName)) {
return false return false
...@@ -79,8 +79,7 @@ async function loadPlugin( ...@@ -79,8 +79,7 @@ async function loadPlugin(
} else if (options === true) { } else if (options === true) {
return createLazyPostCssPlugin(() => require(pluginPath)) return createLazyPostCssPlugin(() => require(pluginPath))
} else { } else {
const keys = Object.keys(options) if (typeof options === 'object' && Object.keys(options).length === 0) {
if (keys.length === 0) {
return createLazyPostCssPlugin(() => require(pluginPath)) return createLazyPostCssPlugin(() => require(pluginPath))
} }
return createLazyPostCssPlugin(() => require(pluginPath)(options)) return createLazyPostCssPlugin(() => require(pluginPath)(options))
...@@ -187,7 +186,9 @@ export async function getPostCssPlugins( ...@@ -187,7 +186,9 @@ export async function getPostCssPlugins(
const pluginConfig = plugin[1] const pluginConfig = plugin[1]
if ( if (
typeof pluginName === 'string' && typeof pluginName === 'string' &&
(typeof pluginConfig === 'boolean' || typeof pluginConfig === 'object') (typeof pluginConfig === 'boolean' ||
typeof pluginConfig === 'object' ||
typeof pluginConfig === 'string')
) { ) {
parsed.push([pluginName, pluginConfig]) parsed.push([pluginName, pluginConfig])
} else { } else {
......
import { createNext } from 'e2e-utils'
import { renderViaHTTP } from 'next-test-utils'
import { NextInstance } from 'test/lib/next-modes/base'
describe('PostCSS plugin config as string', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: {
'pages/index.js': `
export default function Page() {
return <p>hello world</p>
}
`,
'global.css': `
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
`,
'pages/_app.js': `
import "../global.css"
export default function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
`,
'postcss.config.js': `
module.exports = {
plugins: {
'tailwindcss/nesting': 'postcss-nesting',
tailwindcss: {},
},
}
`,
'tailwind.config.js': `
module.exports = {
content: ['./pages/**/*'],
}
`,
},
dependencies: {
'postcss-nesting': '10.1.3',
tailwindcss: '3.0.23',
},
})
})
afterAll(() => next.destroy())
it('should work', async () => {
const html = await renderViaHTTP(next.url, '/')
expect(html).toContain('hello world')
})
})
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