11const path = require ( 'path' )
2- const qs = require ( 'querystring' )
32const Joi = require ( 'joi' )
43const micromatch = require ( 'micromatch' )
54const union = require ( 'lodash.union' )
@@ -28,7 +27,8 @@ module.exports = class Config {
2827 // merges API options into app.js options
2928 let allOpts = merge ( this . parseAppJs ( opts ) , opts )
3029 this . transformSpikeOptionsToWebpack ( this . validateOpts ( allOpts ) )
31- this . project = project
30+ const sp = this . plugins . find ( ( p ) => p . name === 'spikePlugin' )
31+ sp . options . project = project
3232 }
3333
3434 /**
@@ -56,13 +56,14 @@ module.exports = class Config {
5656 value : Joi . array ( ) . items ( Joi . string ( ) ) . single ( )
5757 } ) . default ( { 'js/main' : [ './assets/js/index.js' ] } ) ,
5858 vendor : Joi . array ( ) . single ( ) ,
59- modulesDirectories : Joi . array ( ) . default ( [ 'node_modules' , 'bower_components' ] ) ,
6059 outputDir : Joi . string ( ) . default ( 'public' ) ,
60+ outputPublicPath : Joi . string ( ) ,
6161 plugins : Joi . array ( ) . default ( [ ] ) ,
6262 afterSpikePlugins : Joi . array ( ) . default ( [ ] ) ,
6363 module : Joi . object ( ) . default ( ) . keys ( {
64- loaders : Joi . array ( ) . default ( [ ] )
64+ rules : Joi . array ( ) . default ( [ ] )
6565 } ) ,
66+ devServer : Joi . func ( ) ,
6667 server : Joi . object ( ) . default ( ) . keys ( {
6768 watchOptions : Joi . object ( ) . default ( ) . keys ( {
6869 ignored : Joi . array ( ) . default ( 'node_modules' )
@@ -136,22 +137,15 @@ module.exports = class Config {
136137 return `!${ path . join ( p , i ) } `
137138 } ) )
138139
139- // parse any extra postcss options out to be passed as querystrings
140- const postcssDirectKeys = [ 'plugins' , 'parser' , 'stringifier' , 'syntax' ]
141- res . postcssQuery = { }
142- for ( const k in res . postcss ) {
143- if ( postcssDirectKeys . indexOf ( k ) < 0 ) res . postcssQuery [ k ] = res . postcss [ k ]
144- }
145-
146140 // catch newly added files, put through the pipeline
147141 res . server . files = [ {
148142 match : allWatchedFiles ,
149143 fn : ( event , file ) => {
150144 const util = new SpikeUtils ( this )
151145 const f = path . join ( this . context , file . replace ( p , '' ) )
152- const files = this . spike . files . all
153- if ( files . indexOf ( f ) < 0 && ! util . isFileIgnored ( f ) && event !== 'addDir' ) {
154- this . project . watcher . watch ( [ ] , [ ] , [ f ] )
146+ const opts = util . getSpikeOptions ( )
147+ if ( opts . files . all . indexOf ( f ) < 0 && ! util . isFileIgnored ( f ) && event !== 'addDir' ) {
148+ opts . project . watcher . watch ( [ ] , [ ] , [ f ] )
155149 }
156150 }
157151 } ]
@@ -167,20 +161,20 @@ module.exports = class Config {
167161 */
168162 transformSpikeOptionsToWebpack ( opts ) {
169163 // `disallow` options would break spike if modified.
170- const disallow = [ 'output' , 'resolveLoader' , 'spike' , 'plugins' , 'context' ]
164+ const disallow = [ 'output' , 'resolveLoader' , 'spike' , 'plugins' , 'afterSpikePlugins' , ' context' , 'outputPublicPath ']
171165
172166 // `noCopy` options are spike-specific and shouldn't be directly added to
173167 // webpack's config
174- const noCopy = [ 'root' , 'matchers' , 'env' , 'server' , 'cleanUrls' , 'dumpDirs' , 'ignore' , 'vendor' , 'outputDir' , 'css' , 'postcssQuery ' ]
168+ const noCopy = [ 'root' , 'matchers' , 'env' , 'server' , 'cleanUrls' , 'dumpDirs' , 'ignore' , 'vendor' , 'outputDir' , 'css' , 'postcss' , 'reshape' , 'babel ']
175169
176170 // All options other than `disallow` or `noCopy` are added directly to
177171 // webpack's config object
178172 const filteredOpts = removeKeys ( opts , disallow . concat ( noCopy ) )
179173 Object . assign ( this , filteredOpts )
180174
181175 // `noCopy` options are added under the `spike` property
182- this . spike = { files : { } }
183- Object . assign ( this . spike , filterKeys ( opts , noCopy ) )
176+ const spike = { files : { } }
177+ Object . assign ( spike , filterKeys ( opts , noCopy ) )
184178
185179 // Now we run some spike-specific config transforms
186180 this . context = opts . root
@@ -190,9 +184,15 @@ module.exports = class Config {
190184 filename : '[name].js'
191185 }
192186
187+ // this is sometimes necessary for webpackjsonp loads in old browsers
188+ if ( opts . outputPublicPath ) {
189+ this . output . publicPath = opts . outputPublicPath
190+ }
191+
193192 this . resolveLoader = {
194- root : [
193+ modules : [
195194 path . join ( opts . root ) , // the project root
195+ path . join ( opts . root , 'node_modules' ) , // the project node_modules
196196 path . join ( __dirname , '../node_modules' ) , // spike/node_modules
197197 path . join ( __dirname , '../../../node_modules' ) // spike's flattened deps, via npm 3+
198198 ]
@@ -208,34 +208,45 @@ module.exports = class Config {
208208 const spikeLoaders = [
209209 {
210210 exclude : reIgnores ,
211- loader : `source-loader!postcss-loader?${ qs . stringify ( opts . postcssQuery ) } ` ,
212- _core : 'css'
211+ test : '/core!css' ,
212+ use : [
213+ { loader : 'source-loader' } ,
214+ { loader : 'postcss-loader' , options : opts . postcss }
215+ ]
213216 } , {
214217 exclude : reIgnores ,
215- loader : 'babel-loader' ,
216- _core : 'js'
218+ test : '/core!js' ,
219+ use : [
220+ { loader : 'babel-loader' , options : opts . babel }
221+ ]
217222 } , {
218223 exclude : reIgnores ,
219- loader : 'source-loader!reshape-loader' ,
220- _core : 'html'
224+ test : '/core!html' ,
225+ use : [
226+ { loader : 'source-loader' } ,
227+ { loader : 'reshape-loader' , options : opts . reshape }
228+ ]
221229 } , {
222230 exclude : reIgnores ,
223- loader : 'source-loader' ,
224- _core : 'static'
231+ test : '/core!static' ,
232+ use : [
233+ { loader : 'source-loader' }
234+ ]
225235 }
226236 ]
227237
228- this . module . loaders = spikeLoaders . concat ( opts . module . loaders )
238+ this . module . rules = spikeLoaders . concat ( opts . module . rules )
229239
230240 const util = new SpikeUtils ( this )
241+ const spikePlugin = new SpikePlugin ( util , spike )
231242
232243 this . plugins = [
233244 ...opts . plugins ,
234- new SpikePlugin ( util ) ,
245+ spikePlugin ,
235246 ...opts . afterSpikePlugins ,
236247 new BrowserSyncPlugin ( opts . server , { callback : ( _ , bs ) => {
237248 if ( bs . utils . devIp . length ) {
238- this . project . emit ( 'info' , `External IP: http://${ bs . utils . devIp [ 0 ] } :${ this . spike . server . port } ` )
249+ spike . project . emit ( 'info' , `External IP: http://${ bs . utils . devIp [ 0 ] } :${ spike . server . port } ` )
239250 }
240251 } } )
241252 ]
0 commit comments