1
1
// @flow
2
2
3
+ import path from 'path' ;
3
4
import minimist from 'minimist' ;
4
5
import React from 'react' ;
5
6
import chalk from 'chalk' ;
@@ -125,6 +126,10 @@ export default class WebpackBase {
125
126
hints : false ,
126
127
} ,
127
128
target : this . isServer ( ) ? 'node' : 'web' ,
129
+ node : {
130
+ // don't transform __dirname when running inside Node.
131
+ __dirname : ! this . isServer ( ) ,
132
+ } ,
128
133
resolve : {
129
134
modules : [ 'node_modules' ] ,
130
135
extensions : [
@@ -387,12 +392,11 @@ export default class WebpackBase {
387
392
388
393
const programArgv = minimist ( argv [ '--' ] || [ ] ) ;
389
394
390
- const definedVariables = {
395
+ const definedVariables : Object = {
391
396
'process.env.SIDE' : SIDE ,
392
397
'process.env.BUILD_ENV' : NODE_ENV ,
393
398
'process.env.PROCESS_NAME' : JSON . stringify ( `${ projectMetadata . name } (${ this . isServer ( ) ? 'server' : 'client' } )` ) ,
394
399
$$RJS_VARS$$ : {
395
- FRAMEWORK_CONFIG : JSON . stringify ( frameworkConfig ) ,
396
400
FRAMEWORK_METADATA : JSON . stringify ( frameworkMetadata ) ,
397
401
PROJECT_METADATA : JSON . stringify ( projectMetadata ) ,
398
402
PARSED_ARGV : JSON . stringify ( programArgv ) ,
@@ -406,6 +410,33 @@ export default class WebpackBase {
406
410
NODE_ENV ,
407
411
} ,
408
412
} ;
413
+ } else {
414
+ const outputDirectory = getWebpackSettings ( this . isServer ( ) ) . output . path ;
415
+
416
+ // we only pass build & logs to bundled code
417
+ // as they are the only folders that NEED to exist for the
418
+ // app to run.
419
+ // Using anything else MUST be an error.
420
+
421
+ // We don't give any information to the client bundle as they cannot interact
422
+ // with the filesystem at all and trying to MUST be an error too.
423
+
424
+ // We give the path relative to the output directory so the project can be
425
+ // moved around freely after being built. This can happen when updating a live app: The app will be built
426
+ // in a temporary folder then moved to its final destination.
427
+
428
+ // The path relative path will be transformed into an absolute path at runtime.
429
+
430
+ // all executed JS files will be located at the root of outputDirectory, so we the new absolute path
431
+ // will be the correct one no matter which bundle produces it.
432
+ const FRAMEWORK_CONFIG = {
433
+ directories : {
434
+ logs : path . relative ( outputDirectory , frameworkConfig . directories . logs ) ,
435
+ build : path . relative ( outputDirectory , frameworkConfig . directories . build ) ,
436
+ } ,
437
+ } ;
438
+
439
+ definedVariables . $$RJS_VARS$$ . FRAMEWORK_CONFIG = JSON . stringify ( FRAMEWORK_CONFIG ) ;
409
440
}
410
441
411
442
return definedVariables ;
0 commit comments