Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing the process / environment from a grunt template

Tags:

I have some code in a grunt.js file which is working with 0.3 but breaks on 0.4:

{     dest: '<%= process.env.DEST %>/index.html' } 

In 0.3 process is defined and so I can access variables defined in the environment inside the template when I am e.g. passing file paths to other plugins.

Is there an alternative approach to this which will work in 0.4? Or a way to put a breakpoint in while the template is rendering so that I can see what variables are available?

like image 358
vitch Avatar asked Dec 21 '12 12:12

vitch


People also ask

What is grunt file used for?

Grunt is a JavaScript task runner, a tool used to automatically perform frequent tasks such as minification, compilation, unit testing, and linting. It uses a command-line interface to run custom tasks defined in a file (known as a Gruntfile). Grunt was created by Ben Alman and is written in Node.


1 Answers

The default data is the config object. You can add the environment variable to the config object or just use it directly.

grunt.initConfig({     destination: process.env.DEST,     task: {         target: {             dest: '<%= destination %>/index.html'         }     }, }); 

or

grunt.initConfig({     task: {         target: {             dest: process.env.DEST + '/index.html'         }     }, }); 
like image 81
Sindre Sorhus Avatar answered Oct 29 '22 13:10

Sindre Sorhus