@@ -57,22 +57,26 @@ a(id="entries-outputs")
5757 ### Entries and outputs
5858
5959 You supply Webpack with one or more *entry* files and let it find and incorporate the dependencies that radiate from those entries.
60- The one entry point file in this example is the application's root file, `src/app .ts`:
60+ The one entry point file in this example is the application's root file, `src/main .ts`:
6161
62- + makeExample('webpack/ts-snippets/ webpack.config.snippets.ts ' , 'one-entry' , 'webpack.config.js (single entry)' )( format ="." )
62+ + makeExample('webpack/ts/config/ webpack.common.js ' , 'one-entry' , 'webpack.config.js (single entry)' )( format ="." )
6363
6464:marked
6565 Webpack inspects that file and traverses its `import` dependencies recursively.
6666
67- + makeExample('webpack/ts-snippets/webpack.config.snippets. ts' , 'app-example ' , 'src/app .ts' )( format ="." )
67+ + makeExample('webpack/ts/src/app/app.component. ts' , 'component ' , 'src/main .ts' )( format ="." )
6868
6969:marked
7070 It sees that you're importing *@angular/core* so it adds that to its dependency list for (potential) inclusion in the bundle.
71- It opens the *@angular/core* file and follows _its_ network of `import` statements until it has built the complete dependency graph from `app .ts` down.
71+ It opens the *@angular/core* file and follows _its_ network of `import` statements until it has built the complete dependency graph from `main .ts` down.
7272
7373 Then it **outputs** these files to the `app.js` _bundle file_ designated in configuration:
7474
75- + makeExample('webpack/ts-snippets/webpack.config.snippets.ts' , 'one-output' , 'webpack.config.js (single output)' )( format ="." )
75+ .code-example
76+ code-example( name ="webpack.config.js (single output)" language ="javascript" ) .
77+ output: {
78+ filename: 'app.js'
79+ }
7680
7781:marked
7882 This `app.js` output bundle is a single JavaScript file that contains the application source and its dependencies.
@@ -82,9 +86,19 @@ a(id="entries-outputs")
8286 You probably don't want one giant bundle of everything.
8387 It's preferable to separate the volatile application app code from comparatively stable vendor code modules.
8488
85- Change the configuration so that it has two entry points, `app.ts` and `vendor.ts`:
89+ Change the configuration so that it has two entry points, `main.ts` and `vendor.ts`:
90+
91+ .code-example
92+ code-example( language ="javascript" ) .
93+ entry: {
94+ app: 'src/app.ts',
95+ vendor: 'src/vendor.ts'
96+ },
97+
98+ output: {
99+ filename: '[name].js'
100+ }
86101
87- + makeExample('webpack/ts-snippets/webpack.config.snippets.ts' , 'two-entries' ,'webpack.config.js (two entries)' )( format ="." )
88102:marked
89103 Webpack constructs two separate dependency graphs
90104 and emits *two* bundle files, one called `app.js` containing only the application code and
@@ -110,13 +124,28 @@ a(id="loaders")
110124 Webpack _itself_ only understands JavaScript files.
111125 Teach it to transform non-JavaScript file into their JavaScript equivalents with *loaders*.
112126 Configure loaders for TypeScript and CSS as follows.
113-
114- + makeExample('webpack/ts-snippets/webpack.config.snippets.ts' , 'loaders' , 'webpack.config.js (two entries)' )( format ="." )
127+
128+ .code-example
129+ code-example( language ="javascript" ) .
130+ rules: [
131+ {
132+ test: /\.ts$/,
133+ loader: 'awesome-typescript-loader'
134+ },
135+ {
136+ test: /\.css$/,
137+ loaders: 'style-loader!css-loader'
138+ }
139+ ]
115140
116141:marked
117142 As Webpack encounters `import` statements like these ...
118-
119- + makeExample('webpack/ts-snippets/webpack.config.snippets.ts' , 'imports' )( format ="." )
143+
144+ .code-example
145+ code-example( language ="typescript" ) .
146+ import { AppComponent } from './app.component.ts';
147+
148+ import 'uiframework/dist/uiframework.css';
120149
121150:marked
122151 ... it applies the `test` RegEx patterns. When a pattern matches the filename, Webpack processes the file with the associated loader.
@@ -137,7 +166,11 @@ a(id="plugins")
137166 Webpack has a build pipeline with well-defined phases.
138167 Tap into that pipeline with plugins such as the `uglify` minification plugin:
139168
140- + makeExample('webpack/ts-snippets/webpack.config.snippets.ts' , 'plugins' )( format ="." )
169+ .code-example
170+ code-example( language ="javascript" ) .
171+ plugins: [
172+ new webpack.optimize.UglifyJsPlugin()
173+ ]
141174
142175a( id ="configure-webpack" )
143176.l-main-section
@@ -249,7 +282,10 @@ a#common-resolve
249282
250283 The app will `import` dozens if not hundreds of JavaScript and TypeScript files.
251284 You could write `import` statements with explicit extensions like this example:
252- + makeExample('webpack/ts-snippets/webpack.config.snippets.ts' , 'single-import' )( format ="." )
285+
286+ .code-example
287+ code-example( language ="typescript" ) .
288+ import { AppComponent } from './app.component.ts';
253289
254290:marked
255291 But most `import` statements don't mention the extension at all.
0 commit comments