Editing
Using Grunt With Web Projects
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Configuration == See also [[:Category:Grunt#prerequisites|Grunt prerequisites]] === Preparing a new Grunt project === Installation depends on creating two files, `package.json` and `gruntfile.js`, in the project directory. * `package.json` specifies the project properties and its Grunt library dependencies. * `gruntfile.js` configures the Grunt tasks. The easiest way to install Grunt and Grunt plugins is with <syntaxhighlight lang="bash"> $ npm install <module> --save-dev </syntaxhighlight> The `--save-dev` option updates the `package.json` file with the module name and version. === Workflow === '''N.B.''' while all of the `npm` commands will work fine in the '''git bash''', '''cygwin''', and '''powershell''' shells, the `grunt` command will only work correctly in '''powershell'''. Start at the project's root directory: <syntaxhighlight lang="bash"> $ cd </path/to/project/root> </syntaxhighlight> Create a boilerplate `package.json` file: <syntaxhighlight lang="bash"> $ npm init </syntaxhighlight> Install the latest version of Grunt for the project: <syntaxhighlight lang="bash"> $ npm install grunt --save-dev </syntaxhighlight> Add the `node_modules` directory to `.gitignore`. Add Grunt plugins as necessary, e.g.: <syntaxhighlight lang="bash"> $ npm install grunt-contrib-uglify --save-dev </syntaxhighlight> Configure tasks in `gruntfile.js`: <syntaxhighlight lang="javascript"> module.exports = function(grunt) { // Project configuration. grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), uglify: { options: { banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n' }, build: { src: 'src/<%= pkg.name %>.js', dest: 'build/<%= pkg.name %>.min.js' } } }); // Load the plugin that provides the "uglify" task. grunt.loadNpmTasks('grunt-contrib-uglify'); // Default task(s). grunt.registerTask('default', ['uglify']); }; </syntaxhighlight> === See also === * [http://gruntjs.com/getting-started#preparing-a-new-grunt-project|Grunt: Preparing a New Grunt Project] [[Category:Grunt]] [[Category:JavaScript]] [[Category:Web Development]]
Summary:
Please note that all contributions to Littledamien Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Littledamien Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information