-
Notifications
You must be signed in to change notification settings - Fork 2
Traduction de advanced/lazy-loading.md
#10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
d1054a6
742aed5
f4c00cb
5a0b225
000350e
755b935
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,27 @@ | ||
# Lazy Loading Routes (En) <br><br> *Cette page est en cours de traduction française. Revenez une autre fois pour lire une traduction achevée ou [participez à la traduction française ici](https://github.com/vuejs-fr/vue-router).* | ||
# Les Routes chargeant à la volée | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Je propose Les routes chargées à la voléeou Le chargement à la voléeThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
EDIT : Finalement on garde la 2ème proposition : #10 (comment) |
||
|
||
When building apps with a bundler, the JavaScript bundle can become quite large, and thus affect the page load time. It would be more efficient if we can split each route's components into a separate chunk, and only load them when the route is visited. | ||
Pendant la construction d'applications avec un « bundler », le paquet JavaScript peut devenir un peut lourd, et donc cela peut affecter le temps de chargement de page. Il serait plus efficace si l'on pouvait séparer chaque composants de route dans des fragments séparés, et de ne les charger uniquement lorsque la route est visitée. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
Combining Vue's [async component feature](http://vuejs.org/guide/components.html#Async-Components) and Webpack's [code splitting feature](https://webpack.js.org/guides/code-splitting-require/), it's trivially easy to | ||
lazy-load route components. | ||
|
||
All we need to do is define our route components as async components: | ||
En combinant la [fonctionnalité de composant asynchrone](http://vuejs.org/guide/components.html#Async-Components) de Vue et la [fonctionnalité de séparation de code](https://webpack.js.org/guides/code-splitting-require/) de Webpack, il est très facile de charger à la volée les composants de route. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
Tout ce dont nous avons à faire, c'est de définir les composants de notre route en tant que composants asynchrones : | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
ou
:) |
||
|
||
``` js | ||
const Foo = resolve => { | ||
// require.ensure is Webpack's special syntax for a code-split point. | ||
// require.ensure est une syntaxe spéciale de Webpack pour une séparation de code. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
avec tick et
sans majuscule Je PR l'original |
||
require.ensure(['./Foo.vue'], () => { | ||
resolve(require('./Foo.vue')) | ||
}) | ||
} | ||
``` | ||
|
||
There's also an alternative code-split syntax using AMD style require, so this can be simplified to: | ||
Il y a aussi une alternative à la syntaxe de séparation de code utilisant l'inclusion à la sauce AMD, cela peut être simplifié en : | ||
|
||
``` js | ||
const Foo = resolve => require(['./Foo.vue'], resolve) | ||
``` | ||
|
||
Nothing needs to change in the route config, just use `Foo` as usual: | ||
Rien n'a besoin d'être modifié dans la configuration de la route, utilisez `Foo` comme d'habitude. | ||
|
||
``` js | ||
const router = new VueRouter({ | ||
|
@@ -32,14 +31,14 @@ const router = new VueRouter({ | |
}) | ||
``` | ||
|
||
### Grouping Components in the Same Chunk | ||
### Grouper des composants dans le même morceau | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on traduit
J'ai ajouté l'info dans l'issue des trads now |
||
|
||
Sometimes we may want to group all the components nested under the same route into the same async chunk. To achieve that we need to use [named chunks](https://webpack.js.org/guides/code-splitting-require/#chunkname) by providing a chunk name to `require.ensure` as the 3rd argument: | ||
Parfois on aimerait grouper tous les composants imbriqués sous la même route, dans un seul et même morceau asynchrone. Pour arriver à cela, nous avons besoin d'utiliser les [morceaux nommés](https://webpack.js.org/guides/code-splitting-require/#chunkname) en donnant un nom au morceau en 3ème argument de `require.ensure`. | ||
|
||
``` js | ||
const Foo = r => require.ensure([], () => r(require('./Foo.vue')), 'group-foo') | ||
const Bar = r => require.ensure([], () => r(require('./Bar.vue')), 'group-foo') | ||
const Baz = r => require.ensure([], () => r(require('./Baz.vue')), 'group-foo') | ||
``` | ||
|
||
Webpack will group any async module with the same chunk name into the same async chunk - this also means we don't need to explicitly list dependencies for `require.ensure` anymore (thus passing an empty array). | ||
Webpack groupera tous les modules asynchrones avec le même nom de morceau, dans le même morceau asynchrone — cela signifie aussi que nous n'avons plus besoin de lister explicitement les dépendances pour `require.ensure` (équivaut à passer un tableau vide). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Je laisse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Que pense tu d'aligner nos titres avec le menu, quitte à les raccourcir ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ça marche !