Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8949689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:16:36+00:00 2026-06-15T13:16:36+00:00

Note: This question is only relevant for Grunt 0.3.x and has been left for

  • 0

Note: This question is only relevant for Grunt 0.3.x and has been left for reference. For help with the latest Grunt 1.x release please see my comment below this question.

I’m currently trying to use Grunt.js to setup an automatic build process for first concatenating and then minifying CSS and JavaScript files.

I have been able to successfully concatenate and minify my JavaScript files, although each time I run grunt it seems to just append to the file instead of overwriting them.

As for the minifying or even concatenating CSS, I have been unable to do this as of yet!

In terms of grunt CSS modules I have tried using consolidate-css, grunt-css & cssmin but to no avail. Could not get my head around how to use them!

My directory structure is as follows (being a typical node.js application):

  • app.js
  • grunt.js
  • /public/index.html
  • /public/css/[various css files]
  • /public/js/[various javascript files]

Here is what my grunt.js file currently looks like in the root folder of my application:

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    pkg: '<json:package.json>',
    concat: {
      dist: {
        src: 'public/js/*.js',
        dest: 'public/js/concat.js'
      }
    },
    min: {
      dist: {
        src: 'public/js/concat.js',
        dest: 'public/js/concat.min.js'
      }
    },
    jshint: {
      options: {
        curly: true,
        eqeqeq: true,
        immed: true,
        latedef: true,
        newcap: true,
        noarg: true,
        sub: true,
        undef: true,
        boss: true,
        eqnull: true,
        node: true
      },
      globals: {
        exports: true,
        module: false
      }
    },
    uglify: {}
  });

  // Default task.
  grunt.registerTask('default', 'concat min');

};

So just to summarise I need help with two questions:

  1. How to concatenate and minify all my css files under the folder /public/css/ into one file, say main.min.css
  2. Why does grunt.js keep on appending to the concatenated and minified javascript files concat.js and concat.min.js under /public/js/ instead of overwriting them each time the command grunt is run?

Updated 5th of July 2016 – Upgrading from Grunt 0.3.x to Grunt 0.4.x or 1.x

Grunt.js has moved to a new structure in Grunt 0.4.x (the file is now called Gruntfile.js). Please see my open source project Grunt.js Skeleton for help with setting up a build process for Grunt 1.x.

Moving from Grunt 0.4.x to Grunt 1.x should not introduce many major changes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:16:37+00:00Added an answer on June 15, 2026 at 1:16 pm

    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 all your sources under ./src and your built files under ./dest

    src
    ├── css
    │   ├── 1.css
    │   ├── 2.css
    │   └── 3.css
    └── js
        ├── 1.js
        ├── 2.js
        └── 3.js
    

    Then set up your concat task

    concat: {
      js: {
        src: 'src/js/*.js',
        dest: 'dest/js/concat.js'
      },
      css: {
        src: 'src/css/*.css',
        dest: 'dest/css/concat.css'
      }
    },
    

    Your min task

    min: {
      js: {
        src: 'dest/js/concat.js',
        dest: 'dest/js/concat.min.js'
      }
    },
    

    The build-in min task uses UglifyJS, so you need a replacement. I found grunt-css to be pretty good. After installing it, load it into your grunt file

    grunt.loadNpmTasks('grunt-css');
    

    And then set it up

    cssmin: {
      css:{
        src: 'dest/css/concat.css',
        dest: 'dest/css/concat.min.css'
      }
    }
    

    Notice that the usage is similar to the built-in min.

    Change your default task to

    grunt.registerTask('default', 'concat min cssmin');
    

    Now, running grunt will produce the results you want.

    dest
    ├── css
    │   ├── concat.css
    │   └── concat.min.css
    └── js
        ├── concat.js
        └── concat.min.js
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please note this question related to performance only. Lets skip design guidelines, philosophy, compatibility,
Please note that this question is from 2008 and now is of only historic
(Please note that the behavior described in this question only appeared because of something
Note: I originally asked this question about an hour ago but only recently realized
Note: this question has nothing to do with Knockout.js, but it's about the selectedOptions
Note: This question has broadened in scope from previous revisions. I have tried to
Please retag this question to include languages to which it is relevant So my
Note: I don't think this question has much to do with PHP's eval .
Note: This question is not about making a custom dropdown. It's only about possibilities
Note: This question and most of its answers date to before the release of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.