@@ -19,11 +19,11 @@ import devConfigFactory from './dev.config';
1919import unitConfigFactory from './unit.config' ;
2020import functionalConfigFactory from './functional.config' ;
2121import distConfigFactory from './dist.config' ;
22+ import electronConfigFactory from './electron.config' ;
2223import logger from './logger' ;
2324import { moveBuildOptions } from './util/eject' ;
2425import { readFileSync } from 'fs' ;
2526
26- export const mainEntry = 'main' ;
2727const packageJsonPath = path . join ( process . cwd ( ) , 'package.json' ) ;
2828const packageJson = fs . existsSync ( packageJsonPath ) ? require ( packageJsonPath ) : { } ;
2929export const packageName = packageJson . name || '' ;
@@ -37,20 +37,19 @@ function getLibraryName(name: string) {
3737
3838const libraryName = packageName ? getLibraryName ( packageName ) : 'main' ;
3939
40- const fixMultipleWatchTrigger = require ( 'webpack-mild-compile' ) ;
4140const hotMiddleware = require ( 'webpack-hot-middleware' ) ;
4241const connectInject = require ( 'connect-inject' ) ;
4342
4443const testModes = [ 'test' , 'unit' , 'functional' ] ;
4544
46- function createCompiler ( config : webpack . Configuration ) {
47- const compiler = webpack ( config ) ;
48- fixMultipleWatchTrigger ( compiler ) ;
49- return compiler ;
45+ // for some reason the MultiCompiler type doesn't include hooks, even though they are clearly defined on the
46+ // object coming back.
47+ interface MultiCompilerWithHooks extends webpack . MultiCompiler {
48+ hooks : webpack . compilation . CompilerHooks ;
5049}
5150
52- function createWatchCompiler ( config : webpack . Configuration ) {
53- const compiler = createCompiler ( config ) ;
51+ function createWatchCompiler ( configs : webpack . Configuration [ ] ) {
52+ const compiler = webpack ( configs ) as MultiCompilerWithHooks ;
5453 const spinner = ora ( 'building' ) . start ( ) ;
5554 compiler . hooks . invalid . tap ( '@dojo/cli-build-app' , ( ) => {
5655 logUpdate ( '' ) ;
@@ -83,18 +82,18 @@ function serveStatic(
8382 }
8483}
8584
86- function build ( config : webpack . Configuration , args : any ) {
87- const compiler = createCompiler ( config ) ;
85+ function build ( configs : webpack . Configuration [ ] , args : any ) {
86+ const compiler = webpack ( configs ) ;
8887 const spinner = ora ( 'building' ) . start ( ) ;
89- return new Promise < webpack . Compiler > ( ( resolve , reject ) => {
88+ return new Promise < webpack . MultiCompiler > ( ( resolve , reject ) => {
9089 compiler . run ( ( err , stats ) => {
9190 spinner . stop ( ) ;
9291 if ( err ) {
9392 reject ( err ) ;
9493 }
9594 if ( stats ) {
9695 const runningMessage = args . serve ? `Listening on port ${ args . port } ...` : '' ;
97- const hasErrors = logger ( stats . toJson ( { warningsFilter } ) , config , runningMessage , args ) ;
96+ const hasErrors = logger ( stats . toJson ( { warningsFilter } ) , configs , runningMessage , args ) ;
9897 if ( hasErrors ) {
9998 reject ( { } ) ;
10099 return ;
@@ -125,10 +124,15 @@ function buildNpmDependencies(): any {
125124 }
126125}
127126
128- async function fileWatch ( config : webpack . Configuration , args : any , shouldResolve = false ) {
129- return new Promise < webpack . Compiler > ( ( resolve , reject ) => {
130- const watchOptions = config . watchOptions as webpack . Compiler . WatchOptions ;
131- const compiler = createWatchCompiler ( config ) ;
127+ function fileWatch ( configs : webpack . Configuration [ ] , args : any , shouldResolve = false ) : Promise < webpack . MultiCompiler > {
128+ const [ mainConfig ] = configs ;
129+ let compiler : webpack . MultiCompiler ;
130+
131+ return new Promise < webpack . MultiCompiler > ( ( resolve , reject ) => {
132+ const watchOptions = mainConfig . watchOptions as webpack . Compiler . WatchOptions ;
133+
134+ compiler = createWatchCompiler ( configs ) ;
135+
132136 compiler . watch ( watchOptions , ( err , stats ) => {
133137 if ( err ) {
134138 reject ( err ) ;
@@ -139,7 +143,7 @@ async function fileWatch(config: webpack.Configuration, args: any, shouldResolve
139143 args . port
140144 } \nPlease note the serve option is not intended to be used to serve applications in production.`
141145 : 'watching...' ;
142- logger ( stats . toJson ( { warningsFilter } ) , config , runningMessage , args ) ;
146+ logger ( stats . toJson ( { warningsFilter } ) , configs , runningMessage , args ) ;
143147 }
144148 if ( shouldResolve ) {
145149 resolve ( compiler ) ;
@@ -148,8 +152,9 @@ async function fileWatch(config: webpack.Configuration, args: any, shouldResolve
148152 } ) ;
149153}
150154
151- async function serve ( config : webpack . Configuration , args : any ) {
152- const compiler = args . watch ? await fileWatch ( config , args , true ) : await build ( config , args ) ;
155+ async function serve ( configs : webpack . Configuration [ ] , args : any ) {
156+ const [ mainConfig ] = configs ;
157+
153158 let isHttps = false ;
154159 const base = args . base || '/' ;
155160
@@ -162,19 +167,21 @@ async function serve(config: webpack.Configuration, args: any) {
162167 next ( ) ;
163168 } ) ;
164169
165- const outputDir = ( config . output && config . output . path ) || process . cwd ( ) ;
170+ const compiler = args . watch ? await fileWatch ( configs , args , true ) : await build ( configs , args ) ;
171+
172+ const outputDir = ( mainConfig . output && mainConfig . output . path ) || process . cwd ( ) ;
166173 let btrOptions = args [ 'build-time-render' ] ;
167174 if ( btrOptions ) {
168175 if ( args . singleBundle || ( args . experimental && ! ! args . experimental . speed ) ) {
169176 btrOptions = { ...btrOptions , sync : true } ;
170177 }
171- const jsonpName = ( config . output && config . output . jsonpFunction ) || 'unknown' ;
178+ const jsonpName = ( mainConfig . output && mainConfig . output . jsonpFunction ) || 'unknown' ;
172179 const onDemandBtr = new OnDemandBtr ( {
173180 buildTimeRenderOptions : btrOptions ,
174181 scope : libraryName ,
175182 base,
176- compiler,
177- entries : config . entry ? Object . keys ( config . entry ) : [ ] ,
183+ compiler : compiler . compilers [ 0 ] ,
184+ entries : mainConfig . entry ? Object . keys ( mainConfig . entry ) : [ ] ,
178185 outputPath : outputDir ,
179186 jsonpName
180187 } ) ;
@@ -296,6 +303,13 @@ const command: Command = {
296303 choices : [ 'dist' , 'dev' , 'test' , 'unit' , 'functional' ]
297304 } ) ;
298305
306+ options ( 'target' , {
307+ describe : 'the target' ,
308+ alias : 't' ,
309+ default : 'web' ,
310+ choices : [ 'web' , 'electron' ]
311+ } ) ;
312+
299313 options ( 'watch' , {
300314 describe : 'watch for file changes' ,
301315 alias : 'w'
@@ -356,31 +370,39 @@ const command: Command = {
356370 } ,
357371 run ( helper : Helper , args : any ) {
358372 console . log = ( ) => { } ;
359- let config : webpack . Configuration ;
373+ let configs : webpack . Configuration [ ] = [ ] ;
360374 args . experimental = args . experimental || { } ;
375+ args . base = url . resolve ( '/' , args . base || '' ) ;
376+ if ( ! args . base . endsWith ( '/' ) ) {
377+ args . base = `${ args . base } /` ;
378+ }
361379
362380 if ( args . mode === 'dev' ) {
363- config = devConfigFactory ( args ) ;
381+ configs . push ( devConfigFactory ( args ) ) ;
364382 } else if ( args . mode === 'unit' || args . mode === 'test' ) {
365- config = unitConfigFactory ( args ) ;
383+ configs . push ( unitConfigFactory ( args ) ) ;
366384 } else if ( args . mode === 'functional' ) {
367- config = functionalConfigFactory ( args ) ;
385+ configs . push ( functionalConfigFactory ( args ) ) ;
368386 } else {
369- config = distConfigFactory ( args ) ;
387+ configs . push ( distConfigFactory ( args ) ) ;
388+ }
389+
390+ if ( args . target === 'electron' ) {
391+ configs . push ( electronConfigFactory ( args ) ) ;
370392 }
371393
372394 if ( args . serve ) {
373395 if ( testModes . indexOf ( args . mode ) !== - 1 ) {
374396 return Promise . reject ( new Error ( `Cannot use \`--serve\` with \`--mode=${ args . mode } \`` ) ) ;
375397 }
376- return serve ( config , args ) ;
398+ return serve ( configs , args ) ;
377399 }
378400
379401 if ( args . watch ) {
380- return fileWatch ( config , args ) ;
402+ return fileWatch ( configs , args ) ;
381403 }
382404
383- return build ( config , args ) ;
405+ return build ( configs , args ) ;
384406 } ,
385407 eject ( helper : Helper ) : EjectOutput {
386408 return {
0 commit comments