0

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.

James
  • 1,355
  • 3
  • 14
  • 38
  • 1
    Please edit your question or post a comment instead of editing my answer, what error shows up with the Gruntfile you linked ? – Preview Jun 01 '14 at 19:38
  • Have you run `npm install` ? Also remove all the useless comments that may have inpact on your Gruntfile – Preview Jun 01 '14 at 19:45

2 Answers2

1

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:
        }
    ]
}
Community
  • 1
  • 1
crashbus
  • 1,678
  • 18
  • 37
0

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']);
Preview
  • 35,317
  • 10
  • 92
  • 112
  • hello - any idea how i can svgmin multiple files or directories at the same time? – v3nt Nov 24 '15 at 18:52
  • @danielCrabbe Specify multiple properties in the `files` object? – Preview Nov 24 '15 at 18:54
  • yes - have several svgs to process and even better a wildcard for all svgs in assets/img/ compressed to dist/ – v3nt Nov 24 '15 at 18:59
  • 1
    That was an answer, I mean try to specify them in the `files` object property ;) – Preview Nov 24 '15 at 19:01
  • oh - i've tried adding a few other files but must be getting the format wrong. Also tried the below but obviously not so clued up on some grunt basics! – v3nt Nov 24 '15 at 19:11