I am building a js app on OSX, and Windows 10, both running Node.js v4.2.x.
As part of my build process I run
BUILD_TYPE={my-build-type} gulp build
Which builds a particular configuration of my app, using gulp-preprocess.
The relevant part of my gulp file looks like
var env = process.env;
...
.pipe(plug.preprocess({context: { BUILD_TYPE: env.BUILD_TYPE}}))
...
The relevant part of my HTML looks like
<!-- @if BUILD_TYPE='live' -->
<script src="config/live.js"></script>
<!-- @endif -->
<!-- @if BUILD_TYPE='dev' -->
<script src="config/dev.js"></script>
<!-- @endif -->
<!-- @ifndef BUILD_TYPE -->
<script src="config/dev.js"></script>
<!-- @endif -->
<p>build type - <!-- @echo BUILD_TYPE --></p>
On OSX this works great, running BUILD_TYPE=dev gulp build
results in:
<script src="config/dev.js"></script>
<p>build type - dev</p>
However, on Windows 10, using Node.js command prompt,
set BUILD_TYPE=dev && gulp build
results in:
<p>build type - dev</p>
With no script tags appearing! It's clearly recognised the environment variable, as it's printed by @echo BUILD_TYPE
. However, none of the script elements are present.
Any clues as to why this might be happening would be much appreciated!
Oddly, if I change my gulpfile to:
...
.pipe(plug.preprocess({context: { BUILD_TYPE: 'dev'}}))
...
I get the expected output:
<script src="config/dev.js"></script>
<p>build type - dev</p>
Further still, if I log the variable before invoking preprocess
:
OSX
console.log(env.BUILD_TYPE);
//dev
console.log(typeof env.BUILD_TYPE);
//string
console.log(env.BUILD_TYPE === 'dev');
//true
Windows 10
console.log(env.BUILD_TYPE);
//dev
console.log(typeof env.BUILD_TYPE);
//string
console.log(env.BUILD_TYPE === 'dev');
//false!