danparm
danparm

Reputation: 25

Grunt source file relative path

Why must the leading slash be removed in the source file paths in order for Grunt to properly locate the files? The gruntfile is in the main project older along with the "includes" folder that contains the JS files.

module.exports = function(grunt) {

    var SiteMasterHeaderArray = [
        "/includes/js/knockout/knockout-3.4.0.js",
        "/includes/js/common/common.js" 
    ];

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        uglify: {
            dest: {
                files: {
                    'dest/SiteMasterHeader.js': SiteMasterHeaderArray
                }
            }
        }
    });

    grunt.loadNpmTasks('grunt-contrib-uglify');

    grunt.registerTask('default', ['uglify']);
};

The destination file isn't written because (at least it appears this way to me) that Grunt is searching some other location for these files due to the "/" in the file path. Remove the slash and the function works perfectly.

Upvotes: 2

Views: 1772

Answers (1)

Juan Ferreras
Juan Ferreras

Reputation: 2861

A leading / means it's an absolute path and it's looking for it, starting from the root directory. Without that, it's searching for a relative path from where Gruntfile.js is.

If you'd like paths to be relative to a different folder than Gruntfile, please see grunt.file.setBase or the --base cli option. More information here.

Upvotes: 2

Related Questions