How to concatenate and minify multiple CSS and JavaScript files with Grunt.js (0.3.x)

concat.js is being included in the concat task’s source files public/js/*.js. You could have a task that removes concat.js (if the file exists) before concatenating again, pass an array to explicitly define which files you want to concatenate and their order, or change the structure of your project. If doing the latter, you could put … Read more

Replace a string in a file with nodejs

You could use simple regex: var result = fileAsString.replace(/string to be replaced/g, ‘replacement’); So… var fs = require(‘fs’) fs.readFile(someFile, ‘utf8’, function (err,data) { if (err) { return console.log(err); } var result = data.replace(/string to be replaced/g, ‘replacement’); fs.writeFile(someFile, result, ‘utf8’, function (err) { if (err) return console.log(err); }); });

How to include scripts automatically in a yeoman/grunt project?

I used grunt-include-source Install it: npm install grunt-include-source –save-dev In Gruntfile: Load it before initConfig: module.exports = function (grunt) { … grunt.loadNpmTasks(‘grunt-include-source’); Configure includeSource itself in initConfig: grunt.initConfig({ …, includeSource: { options: { basePath: ‘app’, baseUrl: “https://stackoverflow.com/”, }, server: { files: { ‘.tmp/index.html’: ‘<%= yeoman.app %>/index.html’ } }, dist: { files: { ‘<%= yeoman.dist %>/index.html’: … Read more

How to deploy node app that uses grunt to heroku

npm has a support for a postinstall step (among many others) that might be just what you’re looking for. The node.js heroku buildpack runs this command when you push to heroku to resolve build dependencies: $ npm install –production https://devcenter.heroku.com/articles/nodejs-support#build-behavior If you take a look at the npm documentation, you can setup a series of … Read more

grunt (minimatch/glob) folder exclusion

In the currently-in-development version 0.4.0a, the grunt.file.expand method now supports exclusions, and does so in an arguably less complex way than the underlying minimatch matching library. This is possible because grunt.file.expand accepts multiple patterns (whereas minimatch only accepts one). From the grunt.file.expand documentation: This method accepts either comma separated wildcard patterns or an array of … Read more

Have Grunt generate index.html for different setups

I recently discovered these Grunt v0.4.0 compatible tasks: grunt-preprocess Grunt task around preprocess npm module. grunt-env Grunt task to automate environment configuration for future tasks. Below are snippets from my Gruntfile.js. ENV setup: env : { options : { /* Shared Options Hash */ //globalOption : ‘foo’ }, dev: { NODE_ENV : ‘DEVELOPMENT’ }, prod … Read more

Tried to Load Angular More Than Once

This could be a number of issues: essentially it’s a problem of routeProvider not finding a file and recursively loading the default. For me, it turned out that it wasn’t minification but concatenation of the js that caused the problems. angular.module(‘myApp’).config([‘$routeProvider’, function ($routeProvider) { $routeProvider .when(“https://stackoverflow.com/”, { templateUrl: ‘views/listing.html’, controller: ‘ListingCtrl’ }) .otherwise({ redirectTo: “https://stackoverflow.com/” … Read more