@@ -57,22 +57,26 @@ a(id="entries-outputs")
57
57
### Entries and outputs
58
58
59
59
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`:
61
61
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 ="." )
63
63
64
64
:marked
65
65
Webpack inspects that file and traverses its `import` dependencies recursively.
66
66
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 ="." )
68
68
69
69
:marked
70
70
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.
72
72
73
73
Then it **outputs** these files to the `app.js` _bundle file_ designated in configuration:
74
74
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
+ }
76
80
77
81
:marked
78
82
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")
82
86
You probably don't want one giant bundle of everything.
83
87
It's preferable to separate the volatile application app code from comparatively stable vendor code modules.
84
88
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
+ }
86
101
87
- + makeExample('webpack/ts-snippets/webpack.config.snippets.ts' , 'two-entries' ,'webpack.config.js (two entries)' )( format ="." )
88
102
:marked
89
103
Webpack constructs two separate dependency graphs
90
104
and emits *two* bundle files, one called `app.js` containing only the application code and
@@ -110,13 +124,28 @@ a(id="loaders")
110
124
Webpack _itself_ only understands JavaScript files.
111
125
Teach it to transform non-JavaScript file into their JavaScript equivalents with *loaders*.
112
126
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
+ ]
115
140
116
141
:marked
117
142
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';
120
149
121
150
:marked
122
151
... 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")
137
166
Webpack has a build pipeline with well-defined phases.
138
167
Tap into that pipeline with plugins such as the `uglify` minification plugin:
139
168
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
+ ]
141
174
142
175
a( id ="configure-webpack" )
143
176
.l-main-section
@@ -249,7 +282,10 @@ a#common-resolve
249
282
250
283
The app will `import` dozens if not hundreds of JavaScript and TypeScript files.
251
284
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';
253
289
254
290
:marked
255
291
But most `import` statements don't mention the extension at all.
0 commit comments