docs(webpack): add angular2-template-loader

closes #1825
This commit is contained in:
Foxandxss 2016-07-05 00:46:57 +02:00 committed by Ward Bell
parent 67ee007fb0
commit 341f32d7f6
5 changed files with 15 additions and 8 deletions

View File

@ -45,6 +45,7 @@
}, },
"devDependencies": { "devDependencies": {
"angular-cli": "^1.0.0-beta.5", "angular-cli": "^1.0.0-beta.5",
"angular2-template-loader": "^0.4.0",
"canonical-path": "0.0.2", "canonical-path": "0.0.2",
"concurrently": "^2.1.0", "concurrently": "^2.1.0",
"css-loader": "^0.23.1", "css-loader": "^0.23.1",

View File

@ -24,7 +24,7 @@ module.exports = {
loaders: [ loaders: [
{ {
test: /\.ts$/, test: /\.ts$/,
loader: 'ts' loaders: ['ts', 'angular2-template-loader']
}, },
{ {
test: /\.html$/, test: /\.html$/,

View File

@ -10,7 +10,7 @@ module.exports = {
loaders: [ loaders: [
{ {
test: /\.ts$/, test: /\.ts$/,
loader: 'ts' loaders: ['ts', 'angular2-template-loader']
}, },
{ {
test: /\.html$/, test: /\.html$/,

View File

@ -5,8 +5,8 @@ import '../../public/css/styles.css';
@Component({ @Component({
selector: 'my-app', selector: 'my-app',
template: require('./app.component.html'), templateUrl: './app.component.html',
styles: [require('./app.component.css')] styleUrls: ['./app.component.css']
}) })
export class AppComponent { } export class AppComponent { }
// #enddocregion // #enddocregion

View File

@ -233,9 +233,10 @@ a(id="common-configuration")
:marked :marked
* ts - a loader to transpile our Typescript code to ES5, guided by the `tsconfig.json` file * ts - a loader to transpile our Typescript code to ES5, guided by the `tsconfig.json` file
* angular2-template-loader - loads angular components' template and styles
* html - for component templates * html - for component templates
* images/fonts - Images and fonts are bundled as well. * images/fonts - Images and fonts are bundled as well.
* css - The pattern matches application-wide styles; the second handles component-scoped styles (the ones specified in a component's `styleUrls` metadata property). * css - The pattern matches application-wide styles; the second handles component-scoped styles (the ones specified in a component's `styleUrls` metadata property)
.l-sub-section .l-sub-section
:marked :marked
The first pattern excludes `.css` files within the `/src/app` directories where our component-scoped styles sit. The first pattern excludes `.css` files within the `/src/app` directories where our component-scoped styles sit.
@ -245,6 +246,10 @@ a(id="common-configuration")
The second pattern filters for component-scoped styles and loads them as strings via the `raw` loader — The second pattern filters for component-scoped styles and loads them as strings via the `raw` loader —
which is what Angular expects to do with styles specified in a `styleUrls` metadata property. which is what Angular expects to do with styles specified in a `styleUrls` metadata property.
.l-sub-section
:marked
Multiple loaders can be also chained using the array notation.
:marked :marked
Finally we add two plugins: Finally we add two plugins:
@ -441,9 +446,10 @@ p.
The `HtmlWebpackPlugin` inserts them dynamically at runtime. The `HtmlWebpackPlugin` inserts them dynamically at runtime.
* The `AppComponent` in `app.component.ts` imports the application-wide css with a simple `import` statement. * The `AppComponent` in `app.component.ts` imports the application-wide css with a simple `import` statement.
* The `AppComponent` itself has its own html template and css files which we load with the `require()` method * The `AppComponent` itself has its own html template and css file. WebPack loads them with calls to `require()`.
supplied by Webpack. Webpack stashes those component-scoped files in the `app.js` bundle too. Webpack stashes those component-scoped files in the `app.js` bundle too.
We don't see those calls in our source code; they're added behind the scenes by the `angular2-template-loader` plug-in.
* The `vendor.ts` consists of vendor dependency `import` statements that drive the `vendor.js` bundle. * The `vendor.ts` consists of vendor dependency `import` statements that drive the `vendor.js` bundle.
The application imports these modules too; they'd be duplicated in the `app.js` bundle The application imports these modules too; they'd be duplicated in the `app.js` bundle