issue120:c_c
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue120:c_c [2017/04/29 12:48] – créée auntiee | issue120:c_c [2017/05/12 15:25] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | ===== 1 ===== | ||
+ | ** | ||
As should be common knowledge amongst my regular readers, I spend a lot of my professional time acting as a web developer. Naturally, this means I have to stay apprised of updates and new tools. One of these updates that I’ve been neglecting is updating my webpack from 1.4 to 2.3.2. As such, this month I will cover how I updated to webpack 2.3.2, while still allowing older projects to work with older versions. | As should be common knowledge amongst my regular readers, I spend a lot of my professional time acting as a web developer. Naturally, this means I have to stay apprised of updates and new tools. One of these updates that I’ve been neglecting is updating my webpack from 1.4 to 2.3.2. As such, this month I will cover how I updated to webpack 2.3.2, while still allowing older projects to work with older versions. | ||
Ligne 8: | Ligne 10: | ||
For a long while, I would just npm install -g webpack, so I could run it from my path. Naturally, that meant I had to use the same version for every project, and if I’m planning on updating projects one by one, I couldn’t just jump versions globally. Instead, I removed the globally installed webpack file, and am instead adding webpack to each project’s package.json file. | For a long while, I would just npm install -g webpack, so I could run it from my path. Naturally, that meant I had to use the same version for every project, and if I’m planning on updating projects one by one, I couldn’t just jump versions globally. Instead, I removed the globally installed webpack file, and am instead adding webpack to each project’s package.json file. | ||
+ | ** | ||
+ | Comme doivent le savoir mes lecteurs assidus, je passe une grande partie de mon temps professionnel comme développeur Web. Naturellement, | ||
+ | |||
+ | Les Bases | ||
+ | |||
+ | La méthode que j' | ||
+ | |||
+ | Problèmes | ||
+ | |||
+ | Pendant longtemps, je faisais un npm install -g webpack, pour pouvoir le lancer à partir de mon chemin. Naturellement, | ||
+ | |||
+ | ** | ||
Running webpack | Running webpack | ||
Ligne 22: | Ligne 36: | ||
Keep in mind that webpack 2 has changed the format, and so the file above won’t work for older versions. | Keep in mind that webpack 2 has changed the format, and so the file above won’t work for older versions. | ||
+ | ** | ||
+ | Lancer webpack | ||
+ | |||
+ | Puisque webpack est maintenant relégué dans les répertoires du projet (et non plus dans ma variable $PATH), lancer le webpack tout seul ne marche pas. J'ai alors créé un script dans mon package.json, | ||
+ | |||
+ | Exemple (j' | ||
+ | |||
+ | Des scripts prédéfinis (comme " | ||
+ | |||
+ | Configuration de Webpack | ||
+ | |||
+ | Vous trouverez ma configuration complète ici: https:// | ||
+ | |||
+ | Attention webpack 2 a changé de format, donc les fichiers ci-dessus ne marcheront pas pour des versions antérieures. | ||
+ | |||
+ | |||
+ | ===== 2 ===== | ||
+ | ** | ||
Explanation | Explanation | ||
Ligne 32: | Ligne 64: | ||
The keen-eyed among you probably realized that I’ve not yet talked about my postcss configuration, | The keen-eyed among you probably realized that I’ve not yet talked about my postcss configuration, | ||
+ | ** | ||
+ | Explication | ||
+ | |||
+ | Les lignes var en haut du fichier définissent quelques outils que webpack utilisera. Puis suit la définition du nouveau module.exports, | ||
+ | |||
+ | La toute dernière partie du fichier extrait simplement le texte CSS du fichier js de sortie, et sauve le tout dans un fichier .css. | ||
+ | |||
+ | Mais attendez ! | ||
+ | |||
+ | Les plus observateurs d' | ||
+ | |||
+ | ** | ||
Extra files | Extra files | ||
Ligne 45: | Ligne 89: | ||
Naturally, I could just import the files from within a single stylus or css file, and have one entry in styles.js. However, this can get confusing if you’re importing files that are importing files, and it can be hard to keep track of which imports you added, and which were present from the beginning. That’s why I load all complete stylesheets in the JS file. In the case of mixins (such as variables or functions), I’ll load those only in the files where they are needed, as they won’t otherwise compile. | Naturally, I could just import the files from within a single stylus or css file, and have one entry in styles.js. However, this can get confusing if you’re importing files that are importing files, and it can be hard to keep track of which imports you added, and which were present from the beginning. That’s why I load all complete stylesheets in the JS file. In the case of mixins (such as variables or functions), I’ll load those only in the files where they are needed, as they won’t otherwise compile. | ||
- | I hope this article was useful for anyone who wants to use NPM and upgrade to webpack 2. If you have any questions or comments, feel free to send me an email at lswest34+fcm@gmail.com. | + | I hope this article was useful for anyone who wants to use NPM and upgrade to webpack 2. If you have any questions or comments, feel free to send me an email at lswest34+fcm@gmail.com. |
+ | ** | ||
+ | |||
+ | Fichiers supplémentaires | ||
+ | |||
+ | Les nouvelles versions de postcss et postcss-loader permettent d' | ||
+ | |||
+ | Le fichier en entrée de l' | ||
+ | |||
+ | require(' | ||
+ | require(' | ||
+ | require(' | ||
+ | |||
+ | Bien sûr, je pourrais simplement importer les fichiers d'un seul fichier stylus ou css, et avoir une seule ligne dans styles.js. Mais cela peut prêter à confusion si vous importez des fichiers, et ça peut être difficile de garder la trace des imports que vous avez ajoutés, et qui étaient présents dès le début. C'est pourquoi je charge toutes les feuilles de styles complètes dans le fichier JS. Dans le cas de mélanges (comme les variables ou les fonctions), je le charge uniquement dans les fichiers où on en a besoin, sinon ça ne compilera pas. | ||
+ | |||
+ | J' |
issue120/c_c.1493462889.txt.gz · Dernière modification : 2017/04/29 12:48 de auntiee