@@ -43,10 +43,10 @@ const loaders = ({target, external, minimize, loader}) => {
4343 const styleLoader = require . resolve ( 'style-loader' ) ;
4444 if ( target === 'web' ) {
4545 if ( external ) {
46- return ExtractTextPlugin . extract (
47- styleLoader ,
48- `${ pack ( cssLoader , config ) } !${ loader } `
49- ) ;
46+ return ExtractTextPlugin . extract ( {
47+ fallbackLoader : styleLoader ,
48+ loader : `${ pack ( cssLoader , config ) } !${ loader } ` ,
49+ } ) ;
5050 }
5151 return `${ styleLoader } !${ pack ( cssLoader , config ) } !${ loader } ` ;
5252 }
@@ -57,7 +57,7 @@ export default ({
5757 options = [ ] ,
5858 filename = '[name].css' ,
5959} = { } ) => ( config ) => {
60- const { target} = config ;
60+ const { target = 'web' } = config ;
6161 const env = process . env . NODE_ENV || 'development' ;
6262 const hot = process . env . HOT || false ;
6363 const production = env === 'production' ;
@@ -69,80 +69,84 @@ export default ({
6969 throw new TypeError ( '`options` must be array or function!' ) ;
7070 }
7171
72+ const postcss = ( webpack ) => {
73+ return [
74+ cssimport ( {
75+ // Make webpack acknowledge imported files.
76+ onImport : ( files ) => files . forEach ( ( dep ) =>
77+ webpack . addDependency ( dep ) ) ,
78+ resolve : ( id , { basedir} ) =>
79+ webpack . resolveSync ( basedir , id ) ,
80+ } ) ,
81+ constants ( {
82+ require : ( request , _ , done ) => {
83+ webpack . loadModule ( request , ( err , source ) => {
84+ if ( err ) {
85+ done ( err ) ;
86+ } else {
87+ let result = null ;
88+ try {
89+ result = webpack . exec ( source , request ) ;
90+ // interop for ES6 modules
91+ if ( result . __esModule && result . default ) {
92+ result = result . default ;
93+ }
94+ } catch ( e ) {
95+ done ( e ) ;
96+ return ;
97+ }
98+ // Don't need to call `this.addDependency` since the
99+ // `loadModule` function takes care of it.
100+ done ( null , result ) ;
101+ }
102+ } ) ;
103+ } ,
104+ } ) ,
105+ precss ,
106+ ...( Array . isArray ( options ) ? options : options ( webpack ) ) ,
107+ autoprefixer ( {
108+ browsers : [ 'last 2 versions' ] ,
109+ } ) ,
110+ ] ;
111+ } ;
112+
72113 return partial ( config , {
73114 // Module settings.
74115 module : {
75116 loaders : [ {
76- name : 'postcss' ,
77117 test : IS_STYLE ,
78118 loader : loaders ( {
79119 loader : require . resolve ( 'postcss-loader' ) ,
120+ options : {
121+ postcss,
122+ } ,
80123 target,
81124 external,
82125 minimize,
83126 } ) ,
84127 } , {
85- name : 'js-css' ,
86128 test : IS_CSS_JS ,
87129 loader : loaders ( {
88130 loader : [
89131 require . resolve ( 'postcss-loader' ) ,
90132 require . resolve ( 'css-js-loader' ) ,
91133 ] . join ( '!' ) ,
134+ options : {
135+ postcss,
136+ } ,
92137 target,
93138 external,
94139 minimize,
95140 } ) ,
96141 } ] ,
97142 } ,
98143
99- postcss ( webpack ) {
100- return [
101- cssimport ( {
102- // Make webpack acknowledge imported files.
103- onImport : ( files ) => files . forEach ( ( dep ) =>
104- webpack . addDependency ( dep ) ) ,
105- resolve : ( id , { basedir} ) =>
106- webpack . resolveSync ( basedir , id ) ,
107- } ) ,
108- constants ( {
109- require : ( request , _ , done ) => {
110- webpack . loadModule ( request , ( err , source ) => {
111- if ( err ) {
112- done ( err ) ;
113- } else {
114- let result = null ;
115- try {
116- result = webpack . exec ( source , request ) ;
117- // interop for ES6 modules
118- if ( result . __esModule && result . default ) {
119- result = result . default ;
120- }
121- } catch ( e ) {
122- done ( e ) ;
123- return ;
124- }
125- // Don't need to call `this.addDependency` since the
126- // `loadModule` function takes care of it.
127- done ( null , result ) ;
128- }
129- } ) ;
130- } ,
131- } ) ,
132- precss ,
133- ...( Array . isArray ( options ) ? options : options ( webpack ) ) ,
134- autoprefixer ( {
135- browsers : [ 'last 2 versions' ] ,
136- } ) ,
137- ] ;
138- } ,
139-
140144 plugins : [
141145 ...( external ? [
142146 // Some crawlers or things with Javascript disabled prefer normal CSS
143147 // instead of Javascript injected CSS, so this plugin allows for the
144148 // collection of the generated CSS into its own file.
145- new ExtractTextPlugin ( filename ) ,
149+ new ExtractTextPlugin ( { filename} ) ,
146150 ] : [ ] ) ,
147151 ] ,
148152 } ) ;
0 commit comments