You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/concepts/output.md
+38-30Lines changed: 38 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,32 +2,39 @@
2
2
title: Output
3
3
sort: 3
4
4
contributors:
5
-
- TheLarkInn
5
+
- TheLarkInn
6
6
---
7
7
8
8
Options affecting the output of the compilation. `output` options tell Webpack how to write the compiled files to disk. Note, that while there can be multiple `entry` points, only one `output` configuration is specified.
9
9
10
10
If you use any hashing (`[hash]` or `[chunkhash]`), make sure to have a consistent ordering of modules. Use the `OccurrenceOrderPlugin` or `recordsPath`.
11
11
12
-
##Usage
12
+
# Usage
13
13
14
-
To set the `output` property, you simply set the output value in your webpack config:
14
+
The minimum requirements for the `output` property in your webpack config is to set its value to an object including the following two things :
15
+
16
+
Your preferred `filename` of the compiled file: `// main.js || bundle.js || index.js`
17
+
18
+
An [`output.path`](#output-path) as an **absolute path** for what directory you prefer it to go in once bundled.
15
19
16
20
**webpack.config.js**
17
21
18
22
```javascript
19
23
constconfig= {
20
-
output:'bundle.js'
24
+
output: {
25
+
filename:'bundle.js',
26
+
output:'/home/proj/public/assets'
27
+
}
21
28
};
22
29
23
30
module.exports= config;
24
31
```
25
32
26
-
##Options
33
+
# Options
27
34
28
35
The following is a list of values you can pass to the `output` property.
29
36
30
-
###`output.chunkFilename`
37
+
## `output.chunkFilename`
31
38
32
39
The filename of non-entry chunks as a relative path inside the `output.path` directory.
33
40
@@ -39,7 +46,7 @@ The filename of non-entry chunks as a relative path inside the `output.path` dir
39
46
40
47
`[chunkhash]` is replaced by the hash of the chunk.
41
48
42
-
###`output.crossOriginLoading`
49
+
## `output.crossOriginLoading`
43
50
44
51
This option enables cross-origin loading of chunks.
45
52
@@ -55,10 +62,9 @@ For more information on cross-origin loading see [MDN](https://developer.mozilla
55
62
56
63
> Default: `false`
57
64
58
-
> see also [[library and externals]]
59
-
> see also [[Development Tools]]
65
+
> see also [[library and externals]] see also [[Development Tools]]
60
66
61
-
###`output.devtoolLineToLine`
67
+
## `output.devtoolLineToLine`
62
68
63
69
Enable line-to-line mapped mode for all/specified modules. Line-to-line mapped mode uses a simple SourceMap where each line of the generated source is mapped to the same line of the original source. It's a performance optimization. Only use it if your performance needs to be better and you are sure that input lines match which generated lines.
64
70
@@ -68,12 +74,13 @@ An object `{test, include, exclude}` similar to `module.loaders` enables it for
68
74
69
75
> Default: `false`
70
76
71
-
###`output.filename`
77
+
## `output.filename`
72
78
73
79
Specifies the name of each output file on disk. You must **not** specify an absolute path here! The `output.path` option determines the location on disk the files are written. `filename` is used solely for naming the individual files.
74
80
75
81
**single entry**
76
-
```javascript
82
+
83
+
```javascript
77
84
{
78
85
entry:'./src/app.js',
79
86
output: {
@@ -95,7 +102,7 @@ If your configuration creates more than a single "chunk" (as with multiple entry
95
102
96
103
`[chunkhash]` is replaced by the hash of the chunk.
97
104
98
-
```javascript
105
+
```javascript
99
106
{
100
107
entry: {
101
108
app:'./src/app.js',
@@ -110,7 +117,7 @@ If your configuration creates more than a single "chunk" (as with multiple entry
110
117
// writes to disk: ./build/app.js, ./build/search.js
111
118
```
112
119
113
-
###`output.hotUpdateChunkFilename`
120
+
## `output.hotUpdateChunkFilename`
114
121
115
122
The filename of the Hot Update Chunks. They are inside the `output.path` directory.
116
123
@@ -120,35 +127,35 @@ The filename of the Hot Update Chunks. They are inside the `output.path` directo
120
127
121
128
> Default: `"[id].[hash].hot-update.js"`
122
129
123
-
###`output.hotUpdateFunction`
130
+
## `output.hotUpdateFunction`
124
131
125
132
The JSONP function used by webpack for async loading of hot update chunks.
126
133
127
134
> Default: `"webpackHotUpdate"`
128
135
129
-
###`output.hotUpdateMainFilename`
136
+
## `output.hotUpdateMainFilename`
130
137
131
138
The filename of the Hot Update Main File. It is inside the `output.path` directory.
132
139
133
140
`[hash]` is replaced by the hash of the compilation. (The last hash stored in the records)
134
141
135
142
> Default: `"[hash].hot-update.json"`
136
143
137
-
###`output.jsonpFunction`
144
+
## `output.jsonpFunction`
138
145
139
146
The JSONP function used by webpack for asnyc loading of chunks.
140
147
141
148
A shorter function may reduce the filesize a bit. Use a different identifier when having multiple webpack instances on a single page.
142
149
143
150
> Default: `"webpackJsonp"`
144
151
145
-
###`output.library`
152
+
## `output.library`
146
153
147
154
If set, export the bundle as library. `output.library` is the name.
148
155
149
156
Use this if you are writing a library and want to publish it as single file.
150
157
151
-
###`output.libraryTarget`
158
+
## `output.libraryTarget`
152
159
153
160
Which format to export the library:
154
161
@@ -168,48 +175,49 @@ Which format to export the library:
168
175
169
176
If `output.library` is not set, but `output.libraryTarget` is set to a value other than `var`, every property of the exported object is copied (Except `amd`, `commonjs2` and `umd`).
170
177
171
-
###`output.path`
178
+
## `output.path`
172
179
173
180
The output directory as an **absolute path** (required).
174
181
175
182
`[hash]` is replaced by the hash of the compilation.
176
183
177
-
178
184
**config.js**
179
185
180
-
```javascript
186
+
```javascript
181
187
output: {
182
-
path:"/home/proj/public/assets",
183
-
publicPath:"/assets/"
188
+
path:"/home/proj/public/assets",
189
+
publicPath:"/assets/"
184
190
}
185
191
```
186
192
187
193
**index.html**
188
-
```html
194
+
195
+
```html
189
196
<head>
190
197
<linkhref="/assets/spinner.gif"/>
191
198
</head>
192
199
```
200
+
193
201
And a more complicated example of using a CDN and hashes for assets.
**Note:** In cases when the eventual `publicPath` of output files isn't known at compile time, it can be left blank and set dynamically at runtime in the entry point file. If you don't know the `publicPath` while compiling, you can omit it and set `__webpack_public_path__` on your entry point.
205
213
206
-
```javascript
214
+
```javascript
207
215
__webpack_public_path__ = myRuntimePublicPath
208
216
209
217
// rest of your application entry
210
218
```
211
219
212
-
###`output.sourceMapFilename`
220
+
## `output.sourceMapFilename`
213
221
214
222
The filename of the SourceMaps for the JavaScript files. They are inside the `output.path` directory.
0 commit comments