0

i am new in gruntjs. I have installed grunt. Also have app. I minified the code using grunt build. It created the /dist directory in which all minified versions of file is there.

How to run this distribution code(/dist) for production using grunt. Not able to figure it out. grunt serve command take /app directory by default

NeiL
  • 791
  • 8
  • 35
  • `grunt serve`, depending on how you implemented it (the `grunt-serve` package maybe?) is most probably _NOT_ intended for production use, only during development. The files generated in the `/dist` folder are supposed to go in a production-ready web server like Apache HTTPD, IIS, LightHTTPD and a lot of others. – Sergiu Paraschiv Apr 14 '15 at 10:39
  • @SergiuParaschiv Okay ,now i get it , i am little curious why it is not intended for production use? – – NeiL Apr 14 '15 at 10:45
  • 1
    Because it was not thought out with efficiency in mind. It's purpose is to make it _easy_ to serve files and maybe transform them in the process (less, sass, etc.). During development it generally does not matter how much memory the `serve` task consumes and how much I/O it does, especially if you also use livereload. That does not mean there are no fast NodeJS based servers - Express is quite good. Read this too: http://stackoverflow.com/questions/18345179/how-to-run-grunt-server-in-dist-directory-instead-of-app-directory – Sergiu Paraschiv Apr 14 '15 at 11:16

1 Answers1

1

Use a package like grunt-contrib-connect (enter link description here). First install it:

$ npm install --save-dev grunt-contrib-connect

In your Gruntfile.js

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

// ...
// In your config object
grunt.initConfig({
    // ...
    connect: {
        dist: {
            options: {
                port: 8000,
                base: 'dist',
                keepAlive: true
            }
        }
    }
    // ...
});

Then run your grunt task:

$ grunt connect:dist

And navigate to http://localhost:8000 (or change port in config).

Note: if you use watch, set keepAlive: false.

Thomas Roch
  • 1,208
  • 8
  • 19