gulp-preprocess and environment variables on Windows 10

RYFN

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!
tq303

Have you ensured you are setting the environment variable using no spaces after defining it.

Something like:

set BUILD_TYPE=dev&&gulp build

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Using Grunt to preprocess and replace environment variables

From Dev

Can't change environment variables in windows 10

From Dev

Installing gulp to windows 10

From Dev

Windows 10 System environment variables don't stick

From Dev

How do I set system environment variables in Windows 10?

From Dev

Manipulation with user and system environment variables from command line in Windows 10

From Dev

Windows 10 Environment Path Variables Missing after reboot

From Dev

Environment variables in Windows makefiles

From Dev

How to use Node Environment Variables inside Gulp?

From Dev

Dummy variables and preProcess

From Java

Setting Windows PowerShell environment variables

From Dev

Environment variables in windows phone 8.1

From Dev

Log access to environment variables in windows

From Dev

NPM environment variables not working in windows?

From Dev

Problems with setting environment variables (especially PATH) and using cd with them in cmd in windows 10

From Dev

Preprocess ng-repeat variables?

From Dev

Installing python environment (windows 10)

From Dev

Running 'gulp-preprocess' as part of 'gulp serve' task

From Dev

Set windows environment variables with a batch file

From Dev

Add a jar file to the environment variables windows 8

From Dev

Set case sensitive Windows environment variables in Perl

From Dev

Why python uppercases all environment variables in windows

From Dev

Ruby system call with environment variables in windows

From Dev

Environment variables in meteor command line for windows

From Dev

Windows 7's PATH and environment variables are corrupted

From Dev

Best practice for Windows PATH/environment variables managing?

From Dev

Windows FOR command not expanding system environment variables

From Dev

Global vs User Windows Environment Variables

From Dev

Set case sensitive Windows environment variables in Perl

Related Related

  1. 1

    Using Grunt to preprocess and replace environment variables

  2. 2

    Can't change environment variables in windows 10

  3. 3

    Installing gulp to windows 10

  4. 4

    Windows 10 System environment variables don't stick

  5. 5

    How do I set system environment variables in Windows 10?

  6. 6

    Manipulation with user and system environment variables from command line in Windows 10

  7. 7

    Windows 10 Environment Path Variables Missing after reboot

  8. 8

    Environment variables in Windows makefiles

  9. 9

    How to use Node Environment Variables inside Gulp?

  10. 10

    Dummy variables and preProcess

  11. 11

    Setting Windows PowerShell environment variables

  12. 12

    Environment variables in windows phone 8.1

  13. 13

    Log access to environment variables in windows

  14. 14

    NPM environment variables not working in windows?

  15. 15

    Problems with setting environment variables (especially PATH) and using cd with them in cmd in windows 10

  16. 16

    Preprocess ng-repeat variables?

  17. 17

    Installing python environment (windows 10)

  18. 18

    Running 'gulp-preprocess' as part of 'gulp serve' task

  19. 19

    Set windows environment variables with a batch file

  20. 20

    Add a jar file to the environment variables windows 8

  21. 21

    Set case sensitive Windows environment variables in Perl

  22. 22

    Why python uppercases all environment variables in windows

  23. 23

    Ruby system call with environment variables in windows

  24. 24

    Environment variables in meteor command line for windows

  25. 25

    Windows 7's PATH and environment variables are corrupted

  26. 26

    Best practice for Windows PATH/environment variables managing?

  27. 27

    Windows FOR command not expanding system environment variables

  28. 28

    Global vs User Windows Environment Variables

  29. 29

    Set case sensitive Windows environment variables in Perl

HotTag

Archive