@@ -7,21 +7,8 @@ import postcss from 'postcss';
77
88import Warning from './Warning' ;
99import SyntaxError from './Error' ;
10- import parseOptions from './options' ;
1110import schema from './options.json' ;
12- import { exec , loadConfig , createPostCssPlugins } from './utils' ;
13-
14- function pluginsToArray ( plugins ) {
15- if ( typeof plugins === 'undefined' ) {
16- return [ ] ;
17- }
18-
19- if ( Array . isArray ( plugins ) ) {
20- return plugins ;
21- }
22-
23- return [ plugins ] ;
24- }
11+ import { exec , loadConfig , getArrayPlugins } from './utils' ;
2512
2613/**
2714 * **PostCSS Loader**
@@ -92,52 +79,26 @@ export default async function loader(content, sourceMap, meta = {}) {
9279 ...loadedConfig ,
9380 ...options ,
9481 plugins : [
95- ...pluginsToArray ( loadedConfig . plugins ) ,
96- ...pluginsToArray ( options . plugins ) ,
82+ ...getArrayPlugins ( loadedConfig . plugins , file ) ,
83+ ...getArrayPlugins ( options . plugins , file ) ,
9784 ] ,
9885 } ;
9986
100- let config ;
101-
102- const { length } = Object . keys ( mergedOptions ) . filter ( ( option ) => {
103- switch ( option ) {
104- // case 'exec':
105- // case 'ident':
106- case 'config' :
107- case 'sourceMap' :
108- return false ;
109- default :
110- return option ;
111- }
112- } ) ;
87+ const resultPlugins = mergedOptions . plugins ;
11388
114- if ( length ) {
115- config = parseOptions . call ( this , mergedOptions ) ;
116- }
89+ const { parser, syntax, stringifier } = mergedOptions ;
11790
118- if ( typeof config . options !== 'undefined' ) {
119- if ( typeof config . options . to !== 'undefined' ) {
120- delete config . options . to ;
121- }
122-
123- if ( typeof config . options . from !== 'undefined' ) {
124- delete config . options . from ;
125- }
126- }
127-
128- const plugins = config . plugins || [ ] ;
129-
130- const postcssOptions = Object . assign (
131- {
132- from : file ,
133- map : options . sourceMap
134- ? options . sourceMap === 'inline'
135- ? { inline : true , annotation : false }
136- : { inline : false , annotation : false }
137- : false ,
138- } ,
139- config . options
140- ) ;
91+ const postcssOptions = {
92+ from : file ,
93+ map : options . sourceMap
94+ ? options . sourceMap === 'inline'
95+ ? { inline : true , annotation : false }
96+ : { inline : false , annotation : false }
97+ : false ,
98+ parser,
99+ syntax,
100+ stringifier,
101+ } ;
141102
142103 // Loader Exec (Deprecated)
143104 // https://webpack.js.org/api/loaders/#deprecated-context-properties
@@ -181,7 +142,7 @@ export default async function loader(content, sourceMap, meta = {}) {
181142
182143 // Loader API Exec (Deprecated)
183144 // https://webpack.js.org/api/loaders/#deprecated-context-properties
184- if ( config . exec ) {
145+ if ( mergedOptions . exec ) {
185146 // eslint-disable-next-line no-param-reassign
186147 content = exec ( content , this ) ;
187148 }
@@ -195,8 +156,6 @@ export default async function loader(content, sourceMap, meta = {}) {
195156 postcssOptions . map . prev = sourceMap ;
196157 }
197158
198- const resultPlugins = createPostCssPlugins ( plugins , file ) ;
199-
200159 let result ;
201160
202161 try {
@@ -268,9 +227,7 @@ export default async function loader(content, sourceMap, meta = {}) {
268227 * @requires schema-utils
269228 *
270229 * @requires postcss
271- * @requires postcss-load-config
272230 *
273- * @requires ./options.js
274231 * @requires ./Warning.js
275232 * @requires ./SyntaxError.js
276233 */
0 commit comments