-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add postcss support to vite-plugin (#517)
- Loading branch information
Showing
9 changed files
with
115 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
'@vanilla-extract/vite-plugin': minor | ||
--- | ||
|
||
Add postcss processing to the plugin | ||
|
||
Vite supports postcss processing as a built in feature, but that's lost in dev mode with vanilla-extract because there are no actual css files for vite to pick up. | ||
|
||
The vite plugin now manually runs postcss over the generated css in serve mode, if any postcss config was found. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@vanilla-extract/integration': major | ||
--- | ||
|
||
processVanillaFile is now async |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import type { ResolvedConfig } from 'vite'; | ||
import type { ProcessOptions, Plugin } from 'postcss'; | ||
|
||
export interface PostCSSConfigResult { | ||
options: ProcessOptions; | ||
plugins: Plugin[]; | ||
} | ||
|
||
// Mostly copied from vite's implementation | ||
// https://github.com/vitejs/vite/blob/efec70f816b80e55b64255b32a5f120e1cf4e4be/packages/vite/src/node/plugins/css.ts | ||
export const resolvePostcssConfig = async ( | ||
config: ResolvedConfig, | ||
): Promise<PostCSSConfigResult | null> => { | ||
// inline postcss config via vite config | ||
const inlineOptions = config.css?.postcss; | ||
const inlineOptionsIsString = typeof inlineOptions === 'string'; | ||
|
||
if (inlineOptions && !inlineOptionsIsString) { | ||
const options = { ...inlineOptions }; | ||
|
||
delete options.plugins; | ||
return { | ||
options, | ||
plugins: inlineOptions.plugins || [], | ||
}; | ||
} else { | ||
try { | ||
const searchPath = | ||
typeof inlineOptions === 'string' ? inlineOptions : config.root; | ||
|
||
const postCssConfig = await ( | ||
await import('postcss-load-config') | ||
).default({}, searchPath); | ||
|
||
return { | ||
options: postCssConfig.options, | ||
// @ts-expect-error - The postcssrc options don't agree with real postcss, but it should be ok | ||
plugins: postCssConfig.plugins, | ||
}; | ||
} catch (e: any) { | ||
if (!/No PostCSS Config found/.test(e.message)) { | ||
throw e; | ||
} | ||
return null; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.