@@ -29,7 +29,7 @@ function loadConfig(id, { ctx: configOptions, path: configPath }) {
2929 options : configOptions || { }
3030 }
3131
32- return findPostcssConfig ( ctx , configPath , { argv : false } ) . catch ( handleError )
32+ return findPostcssConfig ( ctx , configPath ) . catch ( handleError )
3333}
3434
3535function escapeClassNameDashes ( str ) {
@@ -59,9 +59,9 @@ export default {
5959 alwaysProcess : true ,
6060 // `test` option is dynamically set in ./loaders
6161 async process ( { code, map } ) {
62- const config = this . options . config ?
63- await loadConfig ( this . id , this . options . config ) :
64- { }
62+ const config = this . options . config
63+ ? await loadConfig ( this . id , this . options . config )
64+ : { }
6565
6666 const options = this . options
6767 const plugins = [
@@ -79,9 +79,9 @@ export default {
7979 require ( 'postcss-modules' ) ( {
8080 // In tests
8181 // Skip hash in names since css content on windows and linux would differ because of `new line` (\r?\n)
82- generateScopedName : process . env . ROLLUP_POSTCSS_TEST ?
83- '[name]_[local]' :
84- '[name]_[local]__[hash:base64:5]' ,
82+ generateScopedName : process . env . ROLLUP_POSTCSS_TEST
83+ ? '[name]_[local]'
84+ : '[name]_[local]__[hash:base64:5]' ,
8585 ...options . modules ,
8686 getJSON ( filepath , json , outpath ) {
8787 modulesExported [ filepath ] = json
@@ -107,11 +107,11 @@ export default {
107107 // Followings are never modified by user config config
108108 from : this . id ,
109109 to : this . id ,
110- map : this . sourceMap ?
111- shouldExtract ?
112- { inline : false , annotation : false } :
113- { inline : true , annotation : false } :
114- false
110+ map : this . sourceMap
111+ ? shouldExtract
112+ ? { inline : false , annotation : false }
113+ : { inline : true , annotation : false }
114+ : false
115115 }
116116 delete postcssOpts . plugins
117117
@@ -123,6 +123,15 @@ export default {
123123 postcssOpts . map . prev = typeof map === 'string' ? JSON . parse ( map ) : map
124124 }
125125
126+ if ( plugins . length === 0 ) {
127+ // Prevent from postcss warning:
128+ // You did not set any plugins, parser, or stringifier. Right now, PostCSS does nothing. Pick plugins for your case on https://www.postcss.parts/ and use them in postcss.config.js
129+ const noopPlugin = postcss . plugin ( 'postcss-noop-plugin' , ( ) => ( ) => {
130+ /* noop */
131+ } )
132+ plugins . push ( noopPlugin ( ) )
133+ }
134+
126135 const res = await postcss ( plugins ) . process ( code , postcssOpts )
127136
128137 for ( const msg of res . messages ) {
@@ -146,9 +155,9 @@ export default {
146155 if ( options . namedExports ) {
147156 const json = modulesExported [ this . id ]
148157 const getClassName =
149- typeof options . namedExports === 'function' ?
150- options . namedExports :
151- ensureClassName
158+ typeof options . namedExports === 'function'
159+ ? options . namedExports
160+ : ensureClassName
152161 // eslint-disable-next-line guard-for-in
153162 for ( const name in json ) {
154163 const newName = getClassName ( name )
@@ -181,9 +190,9 @@ export default {
181190 }
182191 if ( ! shouldExtract && shouldInject ) {
183192 output += `\nimport styleInject from '${ styleInjectPath } ';\nstyleInject(css${
184- Object . keys ( options . inject ) . length > 0 ?
185- `,${ JSON . stringify ( options . inject ) } ` :
186- ''
193+ Object . keys ( options . inject ) . length > 0
194+ ? `,${ JSON . stringify ( options . inject ) } `
195+ : ''
187196 } );`
188197 }
189198
0 commit comments