Skip to content

Commit 8eca40b

Browse files
davideastjelbourn
authored andcommitted
docs: update getting started w/ webpack CLI (#1237)
1 parent 484f470 commit 8eca40b

File tree

1 file changed

+16
-96
lines changed

1 file changed

+16
-96
lines changed

GETTING_STARTED.md

Lines changed: 16 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,48 @@
1-
This guide will take you through building your first project with Angular Material 2. We'll be using
2-
the Angular CLI, but you can also accomplish this with other build tools like Webpack or Gulp.
1+
Get started with Angular Material 2 using the Angular CLI.
32

4-
### Globally install the CLI
3+
## Install the CLI
54

65
```bash
7-
npm install -g angular-cli
6+
npm install -g angular-cli@webpack
87
```
98

10-
### Create a new project
9+
## Create a new project
1110

1211
```bash
1312
ng new my-project
1413
```
15-
16-
This will create a starter repo under the name you specified with the files and folders
17-
you'd need for any Angular 2 app: a root component, a main.ts to bootstrap your root component, an
18-
index.html, etc. It also sets up build rules to transpile your Typescript into Javascript and sets
19-
some initial config for the SystemJS module loader.
20-
21-
### Install Angular Material 2 components
2214

23-
Now that your project has been created, you can install any Angular Material 2 components you'd like
24-
to use through npm. You can see our [list of published packages here](https://www.npmjs.com/~angular2-material).
15+
The new command creates a project with a build system for your Angular app.
16+
17+
## Install Angular Material 2 components
18+
19+
Angular Material 2 components are set up in separate modules. This allows you to only pull into your app what you need, reducing the size of your app. Components are installed individually. You can see our [list of published packages here](https://www.npmjs.com/~angular2-material).
2520

2621
Note that only packages published under the `@latest` npm tag are officially released.
2722

2823
```bash
2924
npm install --save @angular2-material/core @angular2-material/button @angular2-material/card
3025
```
31-
(the core module is required as a peer dependency of other components)
32-
33-
### Add components to vendor bundle
34-
35-
Next, you'll need to build the `@angular2-material` folder out of `node_modules` and into
36-
`dist/vendor`, so that it's served with the rest of the vendor files. You can easily configure this by
37-
editing the `angular-cli-build.js` file in the root of your project. Simply add a glob for all
38-
@angular2-material files to the end of the existing `vendorNpmFiles` array.
39-
40-
**angular-cli-build.js**
41-
```js
42-
module.exports = function(defaults) {
43-
return new Angular2App(defaults, {
44-
vendorNpmFiles: [
45-
'systemjs/dist/system-polyfills.js',
46-
'systemjs/dist/system.src.js',
47-
'zone.js/dist/**/*.+(js|js.map)',
48-
'es6-shim/es6-shim.js',
49-
'reflect-metadata/**/*.+(js|js.map)',
50-
'rxjs/**/*.+(js|js.map)',
51-
'@angular/**/*.+(js|js.map)',
52-
'@angular2-material/**/*'
53-
]
54-
});
55-
};
56-
```
57-
58-
You can see an example `angular-cli-build.js` file [here](https://github.com/kara/puppy-love/blob/master/angular-cli-build.js).
59-
60-
### Configure SystemJS
61-
62-
First, you need to let SystemJS know where to look when you import `@angular2-material`. You can do
63-
this by adding the path to the Material folder to the `maps` object.
64-
65-
**src/system-config.ts**
66-
```ts
67-
const map: any = {
68-
'@angular2-material': 'vendor/@angular2-material'
69-
};
70-
```
71-
72-
This says something like "when you look for an @angular2-material import, look inside the vendor
73-
folder" (the base folder will already be `dist`).
74-
75-
Next, you need to let SystemJS know how to process the new modules. Specifically, you need to point
76-
to the main files of each of the packages. You can also set the format to `cjs` and the
77-
defaultExtension to `js`, but it's not required.
78-
79-
**src/system-config.ts**
80-
```ts
81-
const packages:any = {};
82-
83-
// put the names of any of your Material components here
84-
const materialPkgs:string[] = [
85-
'core',
86-
'button',
87-
'card',
88-
];
89-
90-
materialPkgs.forEach((pkg) => {
91-
packages[`@angular2-material/${pkg}`] = {main: `${pkg}.js`};
92-
});
93-
```
94-
95-
You can see an example `system-config.ts` [here](https://github.com/kara/puppy-love-io/blob/master/src/system-config.ts).
9626

97-
### Import and use the components
27+
> The core module is required as a peer dependency of other components
9828
99-
Now you should be able to import the components normally wherever you'd like to use them.
29+
## Add components to your app module
30+
Now you should be able to import the components normally wherever you'd like to use them. Import the components in your application module:
10031

101-
**src/app/my-project.component.ts**
32+
**src/app/app.module.ts**
10233
```ts
103-
import { MdCardModule } from '@angular2-material/card';
10434
import { MdButtonModule } from '@angular2-material/button';
105-
```
106-
107-
Import the components in your application module:
108-
109-
**my-app-module.ts**
110-
```ts
35+
import { MdCardModule } from '@angular2-material/card';
36+
// other imports
11137
@NgModule({
11238
imports: [MdButtonModule, MdCardModule],
11339
...
11440
})
11541
```
11642

117-
### Sample Angular Material 2 projects
118-
43+
### Sample Angular Material 2 project
11944
- [Material 2 Sample App](https://github.com/jelbourn/material2-app)
12045

121-
(the following are slightly out of date now)
122-
- [Puppy Love (ng-conf 2016)](https://github.com/kara/puppy-love) - see live demo [here](https://youtu.be/rRiV_b3WsoY?t=4m20s)
123-
- [Puppy Love Mobile (Google IO 2016)](https://github.com/kara/puppy-love-io)
124-
12546

12647
### Additional setup for `md-menu` and `md-tooltip`:
12748
For alpha.7, you need to include the overlay styles in your app via a `link` element. This will
@@ -132,7 +53,6 @@ look something like
13253

13354
In future releases, all of the core styles will be combined into a single distributed css file.
13455

135-
13656
### Additional setup for `md-slide-toggle` and `md-slider`:
13757
The slide-toggle and slider components have a dependency on [HammerJS](http://hammerjs.github.io/).
13858
1) Add HammerJS to your application via [npm](https://www.npmjs.com/package/hammerjs), a CDN

0 commit comments

Comments
 (0)