Gist contenant les parties de code de l'article "Grunt, un lanceur de tâches javascript 2/3"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install -g grunt-cli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm init | |
# Répondez aux quelques questions simples pour créer le package.json | |
npm install grunt --save-dev | |
# Le save-dev permet d'ajouter la dépendance dans le package.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(grunt) { }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(grunt) { | |
grunt.initConfig({ | |
// Configuration des tâches | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function (grunt) { | |
// Charge les plugins Grunt automatiquement | |
require('load-grunt-tasks')(grunt); | |
grunt.initConfig({ | |
// Configuration des tâches | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install load-grunt-tasks --save-dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function (grunt) { | |
// Charge les plugins Grunt automatiquement | |
require('load-grunt-tasks')(grunt); | |
grunt.initConfig({ | |
// Configuration des tâches | |
}); | |
// La liste de tâches est vide, nous la remplirons par la suite. | |
grunt.registerTask('build', []); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install --save-dev grunt-contrib-copy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grunt.initConfig({ | |
copy: { | |
dist: { | |
src: ['*.html', 'images/**/*'], | |
// Vous pouvez bien sûr rajouter d'autres fichiers selon les besoins | |
dest: 'dist/' | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grunt.registerTask('build', ['copy:dist']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install --save-dev grunt-contrib-clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// La configuration | |
clean: { | |
dist: ['dist/*'] | |
} | |
// [...] | |
// On rajoute la sous-tâche "dist" de la tâche "clean". | |
grunt.registerTask('build', ['clean:dist', 'copy:dist']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install --save-dev grunt-contrib-cssmin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cssmin: { | |
dist: { // Le nom de notre sous-tâche est "dist" | |
files: { | |
'dist/public/global.min.css': ['css/**/*.css'] | |
// On regroupe tous les fichiers CSS minifiés dans un global.min.css | |
} | |
} | |
} | |
// [...] | |
// On n'oublie pas de rajouter la tâche à notre build | |
grunt.registerTask('build', ['clean:dist', 'copy:dist', 'cssmin:dist']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install --save-dev grunt-contrib-uglify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uglify: { | |
dist: { | |
files: { | |
'dist/public/scripts.min.js': ['js/**/*.js'] | |
} | |
} | |
} | |
// [...] | |
grunt.registerTask('build', ['clean:dist', 'copy:dist', 'cssmin:dist', 'uglify:dist']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- build:{type} {destination} --> | |
{...} | |
<!-- endbuild --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install --save-dev grunt-usemin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Pour les CSS : --> | |
<!-- build:css public/global.css --> | |
<link rel="stylesheet" href="css/main.css" type="text/css" /> | |
<!-- endbuild --> | |
<!-- Pour les JS : --> | |
<!-- build:js public/scripts.js --> | |
<script src="js/add.js"></script> | |
<script src="js/substract.js"></script> | |
<!-- endbuild --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
useminPrepare: { | |
html: { | |
src: ['index.html'] | |
}, | |
options: { | |
flow: { | |
steps: { | |
js: ['uglifyjs'], | |
css: ['cssmin'], | |
}, | |
post: {} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
usemin: { | |
html: 'dist/index.html' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grunt.registerTask('build', [ | |
'clean:dist', | |
'copy:dist', | |
'useminPrepare', | |
'cssmin', | |
'uglify', | |
'usemin' | |
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grunt build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo apt-get install nodejs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment