|
5 | 5 | [](https://codecov.io/gh/dojo/cli-build-app) |
6 | 6 | [](https://badge.fury.io/js/%40dojo%2Fcli-build-app) |
7 | 7 |
|
8 | | -The official CLI command for building Dojo applications. |
| 8 | +The official CLI command for building optimized Dojo applications. |
9 | 9 |
|
10 | 10 | - [Usage](#usage) |
11 | 11 | - [Features](#features) |
12 | 12 | - [Building](#building) |
| 13 | + - [Code Splitting By Route](#code-splitting-by-route) |
13 | 14 | - [Serving](#serving-the-application) |
14 | 15 | - [Watching](#watching) |
15 | 16 | - [Eject](#eject) |
@@ -59,6 +60,59 @@ The `unit` mode creates bundles that can be used to run the unit tests of the ap |
59 | 60 |
|
60 | 61 | The `functional` mode creates bundles that can be used to run the functional tests of the application. |
61 | 62 |
|
| 63 | +### Code Splitting By Route |
| 64 | + |
| 65 | +The build command will automatically code split your application based on it's dojo routing configuration. |
| 66 | + |
| 67 | +To enable the code automatic splitting by route: |
| 68 | + |
| 69 | +1) The dojo routing configuration needs to be the default export from a `routes.ts` module in the `src` directory. |
| 70 | +2) Widgets must by the default export of their module. |
| 71 | +3) When defining the `Outlet`, the `renderer` function must be defined inline. |
| 72 | + |
| 73 | +```ts |
| 74 | +// routes.ts |
| 75 | +export default [ |
| 76 | + { |
| 77 | + path: 'foo', |
| 78 | + outlet: 'foo', |
| 79 | + children: [ |
| 80 | + { |
| 81 | + path: 'bar', |
| 82 | + outlet: 'bar' |
| 83 | + } |
| 84 | + ] |
| 85 | + }, |
| 86 | + { |
| 87 | + path: 'bar', |
| 88 | + outlet: 'bar' |
| 89 | + } |
| 90 | +]; |
| 91 | +``` |
| 92 | + |
| 93 | +```ts |
| 94 | +// widget |
| 95 | +import WidgetBase from '@dojo/framework/widget-core/WidgetBase'; |
| 96 | +import { v, w } from '@dojo/framework/widget-core/d'; |
| 97 | +import Outlet from '@dojo/framework/routing/Outlet'; |
| 98 | + |
| 99 | +import FooWidget from './FooWidget'; |
| 100 | +import BarWidget from './BarWidget'; |
| 101 | + |
| 102 | +export default class App extends WidgetBase { |
| 103 | + protected render() { |
| 104 | + return v('div', [ |
| 105 | + w(Outlet, { id: 'foo', renderer: () => w(FooWidget, {})}), |
| 106 | + w(Outlet, { id: 'bar', renderer: () => w(BarWidget, {})}) |
| 107 | + ]); |
| 108 | + } |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +The output will result in a separate bundle for each of the application's top level routes. In this example, there will be a main application bundle and two further bundles for `src/FooWidget` and `src/BarWidget`. |
| 113 | + |
| 114 | +**Note:** The configuration can be further refined using the bundle configuration in the `.dojorc`, see [bundles configuration](#bundles:-object). |
| 115 | + |
62 | 116 | ### Serving the Application |
63 | 117 |
|
64 | 118 | A web server can be started with the `--serve` flag while running in `dev` or `dist` modes. By default, the application is served on port 9999, but this can be changed with the `--port` (`-p`) flag: |
|
0 commit comments