File tree Expand file tree Collapse file tree 2 files changed +36
-2
lines changed
packages/esbuild-plugin/src Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @vanilla-extract/esbuild-plugin ' : minor
3+ ---
4+
5+ Add ` processCss ` plugin option to allow further processing of CSS while bundling.
6+
7+ ** Example for postcss with autoprefixer:**
8+
9+ ``` js
10+ const { vanillaExtractPlugin } = require (' @vanilla-extract/esbuild-plugin' );
11+ const postcss = require (' postcss' );
12+ const autoprefixer = require (' autoprefixer' );
13+
14+ require (' esbuild' ).build ({
15+ entryPoints: [' app.ts' ],
16+ bundle: true ,
17+ plugins: [vanillaExtractPlugin ({
18+
19+ processCss: async (css ) => {
20+ return (await postcss ([autoprefixer])
21+ .process (css, { from: undefined /* suppress source map warning */ })
22+ ).css
23+ }
24+
25+ })],
26+ outfile: ' out.js' ,
27+ }).catch (() => process .exit (1 ))
28+ ```
Original file line number Diff line number Diff line change @@ -14,11 +14,13 @@ interface VanillaExtractPluginOptions {
1414 outputCss ?: boolean ;
1515 externals ?: Array < string > ;
1616 runtime ?: boolean ;
17+ processCss ?: ( css : string ) => Promise < string > ;
1718}
1819export function vanillaExtractPlugin ( {
1920 outputCss,
2021 externals = [ ] ,
2122 runtime = false ,
23+ processCss,
2224} : VanillaExtractPluginOptions = { } ) : Plugin {
2325 if ( runtime ) {
2426 // If using runtime CSS then just apply fileScopes to code
@@ -37,8 +39,12 @@ export function vanillaExtractPlugin({
3739
3840 build . onLoad (
3941 { filter : / .* / , namespace : vanillaCssNamespace } ,
40- ( { path } ) => {
41- const { source } = getSourceFromVirtualCssFile ( path ) ;
42+ async ( { path } ) => {
43+ let { source } = getSourceFromVirtualCssFile ( path ) ;
44+
45+ if ( typeof processCss === 'function' ) {
46+ source = await processCss ( source ) ;
47+ }
4248
4349 return {
4450 contents : source ,
You can’t perform that action at this time.
0 commit comments