Introduction aux outils Grunt, Bower, Yeoman et en quoi ils sont liés. Dans cette session, nous présenterons les bienfaits de l’automatisation, notamment dans les projets web complexes. De nombreux scénarios d’usages seront présentés.
4. tech.days 2015#mstechdays
Gestion des dépendances
Compilation / Minification / Tests / Linting
Développement
Tâches récurrentes d’un projet web
Comment automatiser le développement d'un projet web SPA
5. tech.days 2015#mstechdays
Node.JS
Scripts simples mais puissant
Projet web donc javascript !
Outils d’automatisation
Comment automatiser le développement d'un projet web SPA
6. tech.days 2015#mstechdays
Bower ?
Grunt ?
Yeoman ?
Outils d’automatisation
Comment automatiser le développement d'un projet web SPA
8. tech.days 2015#mstechdays
Gestionnaire de librairies JS / CSS
Utilisé pour installer et mettre à jour les librairies
Assure l’intégrité des versions
Définition
Comment automatiser le développement d'un projet web SPA
9. tech.days 2015#mstechdays
Registre de librairies JS / CSS
Enregistre les versions dans un fichier bower.json
Arbre de dépendances plat
Comment ça marche ?
Comment automatiser le développement d'un projet web SPA
13. tech.days 2015#mstechdays
Gestionnaire de tâches Node.JS
Automatise les tâches récurrentes
Enormément de tâches dans NPM
Définition
Comment automatiser le développement d'un projet web SPA
14. tech.days 2015#mstechdays
Configuration dans un fichier Gruntfile.js
Tâches dans NPM ou en local
Simple !!
Comment ça marche ?
Comment automatiser le développement d'un projet web SPA
19. tech.days 2015#mstechdays
Gestionnaire de template de projets
Simplifie la création de projet et d’éléments
Force l’utilisation de bonnes pratiques
Définition
Comment automatiser le développement d'un projet web SPA
20. tech.days 2015#mstechdays
Générateurs dans NPM
Utilise Bower pour gérer les dépendances
Utilise Grunt pour gérer les tâches de compilation
Comment ça marche ?
Comment automatiser le développement d'un projet web SPA
21. Yeoman
# install yeoman
$ npm install –g yo
# install generator
$ npm install –g generator-backbone
# run generator
$ yo backbone
# run sub generator
$ yo backbone:model user
24. Create a simple Grunt Task
module.exports = function (grunt) {
grunt.registerTask("myCustomTask", function () {
// read package.json to get version
var pkg = grunt.file.readJSON("package.json");
// get the version.js content
var content = grunt.file.read("version.js");
// replace the tag {{version}} by the package’s version
content = content.replace("{{version}}", pkg.version);
// write the new content into version.js
grunt.file.write("version.js", content);
});
};
25. Create a multi Grunt Task
module.exports = function (grunt) {
grunt.registerMultiTask("myVersionTask", function () {
var pkg = grunt.file.readJSON("package.json");
// loop over configured files
this.files.forEach(function (file) {
// loop over src / dest match
file.src.forEach(function (src) {
var content = grunt.file.read(src);
content = content.replace("{{version}}", pkg.version);
grunt.file.write("version.js", file.dest);
});
});
});
};
26. Create a multi Grunt Task
module.exports = function (grunt) {
grunt.initConfig({
// task config
myVersionTask: {
dist: {
src: "app/**/*.js",
dest: "dist/"
}
}
});
// load task from local directory
grunt.loadTasks("tasks");
// alias task
grunt.registerTask("build", ["myVersionTask:dist"]);
};
34. tech.days 2015#mstechdays
Slides :
http://fr.slideshare.net/Touchify/grunt-bower-yeoman-ou-comment-
automatiser-un-projet-web-spa
Démo :
https://github.com/spatools/techdays2015
Documentations :
http://bower.io http://gruntjs.com http://yeoman.io
Liens
Comment automatiser le développement d'un projet web SPA