James
James

Reputation: 1475

Grunt task svgmin

Following the setup for grunt svgmin when I run grunt I get the following error

Loading "Gruntfile.js" tasks...ERROR
SyntaxError: Unexpected identifier
Warning: Task "default" not found. Use --force to continue.

My grunt file MY package.json file

I get the above error in terminal when I run grunt I know its something silly Im doing as its all new to me but have spent a coupl eof hours trying to work it out.

Upvotes: 0

Views: 2885

Answers (2)

crashbus
crashbus

Reputation: 1714

I have had a similar error. In my case this error happens when the tools tries to optimize webfont-files saved as .svg. You can avoid this error by ignoring the directory of the fonts (with an ! before the path) or specify the directory where svgs are stored like:

dist: {
    files: [
        {
            expand: true,
            cwd: basePath,
            src: ['images/**/*.svg'],
            dest: 'dist/your_path',
            ext: '.svg'
            // ie:
        }
    ]
}

Upvotes: 1

Preview
Preview

Reputation: 35806

To use the grunt command, you need to register a default task that load some others, like the svgmin one.

grunt.registerTask('default', ['svgmin']);

Remember that you need to install grunt-svgmin with npm :

npm install --save-dev grunt-svgmin

And load it in your Gruntfile just before your registerTask

grunt.loadNpmTasks('grunt-svgmin');

Here an example extracted from their GitHub Readme.

grunt.initConfig({                                                                 
    svgmin: {                                                                      
        options: {                                                                 
            plugins: [ { removeViewBox: false }, { removeUselessStrokeAndFill: false } ] 
        },                                                                         
        dist: {                                                                    
           files: {                                                               
                'dist/figure.svg': 'app/figure.svg'                                
            }                                                                      
        }                                                                          
    }                                                                              
});
grunt.loadNpmTasks('grunt-svgmin');
grunt.registerTask('default', ['svgmin']);

Upvotes: 0

Related Questions