Skip to content

Commit cc56e28

Browse files
committed
modified output concept file to put required options up top and link to bottom
1 parent 7cb1fcb commit cc56e28

File tree

1 file changed

+38
-30
lines changed

1 file changed

+38
-30
lines changed

content/concepts/output.md

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,39 @@
22
title: Output
33
sort: 3
44
contributors:
5-
- TheLarkInn
5+
- TheLarkInn
66
---
77

88
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.
99

1010
If you use any hashing (`[hash]` or `[chunkhash]`), make sure to have a consistent ordering of modules. Use the `OccurrenceOrderPlugin` or `recordsPath`.
1111

12-
## Usage
12+
# Usage
1313

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.
1519

1620
**webpack.config.js**
1721

1822
```javascript
1923
const config = {
20-
output: 'bundle.js'
24+
output: {
25+
filename: 'bundle.js',
26+
output: '/home/proj/public/assets'
27+
}
2128
};
2229

2330
module.exports = config;
2431
```
2532

26-
## Options
33+
# Options
2734

2835
The following is a list of values you can pass to the `output` property.
2936

30-
### `output.chunkFilename`
37+
## `output.chunkFilename`
3138

3239
The filename of non-entry chunks as a relative path inside the `output.path` directory.
3340

@@ -39,7 +46,7 @@ The filename of non-entry chunks as a relative path inside the `output.path` dir
3946

4047
`[chunkhash]` is replaced by the hash of the chunk.
4148

42-
### `output.crossOriginLoading`
49+
## `output.crossOriginLoading`
4350

4451
This option enables cross-origin loading of chunks.
4552

@@ -55,10 +62,9 @@ For more information on cross-origin loading see [MDN](https://developer.mozilla
5562

5663
> Default: `false`
5764
58-
> see also [[library and externals]]
59-
> see also [[Development Tools]]
65+
> see also [[library and externals]] see also [[Development Tools]]
6066
61-
### `output.devtoolLineToLine`
67+
## `output.devtoolLineToLine`
6268

6369
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.
6470

@@ -68,12 +74,13 @@ An object `{test, include, exclude}` similar to `module.loaders` enables it for
6874

6975
> Default: `false`
7076
71-
### `output.filename`
77+
## `output.filename`
7278

7379
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.
7480

7581
**single entry**
76-
``` javascript
82+
83+
```javascript
7784
{
7885
entry: './src/app.js',
7986
output: {
@@ -95,7 +102,7 @@ If your configuration creates more than a single "chunk" (as with multiple entry
95102

96103
`[chunkhash]` is replaced by the hash of the chunk.
97104

98-
``` javascript
105+
```javascript
99106
{
100107
entry: {
101108
app: './src/app.js',
@@ -110,7 +117,7 @@ If your configuration creates more than a single "chunk" (as with multiple entry
110117
// writes to disk: ./build/app.js, ./build/search.js
111118
```
112119

113-
### `output.hotUpdateChunkFilename`
120+
## `output.hotUpdateChunkFilename`
114121

115122
The filename of the Hot Update Chunks. They are inside the `output.path` directory.
116123

@@ -120,35 +127,35 @@ The filename of the Hot Update Chunks. They are inside the `output.path` directo
120127

121128
> Default: `"[id].[hash].hot-update.js"`
122129
123-
### `output.hotUpdateFunction`
130+
## `output.hotUpdateFunction`
124131

125132
The JSONP function used by webpack for async loading of hot update chunks.
126133

127134
> Default: `"webpackHotUpdate"`
128135
129-
### `output.hotUpdateMainFilename`
136+
## `output.hotUpdateMainFilename`
130137

131138
The filename of the Hot Update Main File. It is inside the `output.path` directory.
132139

133140
`[hash]` is replaced by the hash of the compilation. (The last hash stored in the records)
134141

135142
> Default: `"[hash].hot-update.json"`
136143
137-
### `output.jsonpFunction`
144+
## `output.jsonpFunction`
138145

139146
The JSONP function used by webpack for asnyc loading of chunks.
140147

141148
A shorter function may reduce the filesize a bit. Use a different identifier when having multiple webpack instances on a single page.
142149

143150
> Default: `"webpackJsonp"`
144151
145-
### `output.library`
152+
## `output.library`
146153

147154
If set, export the bundle as library. `output.library` is the name.
148155

149156
Use this if you are writing a library and want to publish it as single file.
150157

151-
### `output.libraryTarget`
158+
## `output.libraryTarget`
152159

153160
Which format to export the library:
154161

@@ -168,48 +175,49 @@ Which format to export the library:
168175
169176
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`).
170177

171-
### `output.path`
178+
## `output.path`
172179

173180
The output directory as an **absolute path** (required).
174181

175182
`[hash]` is replaced by the hash of the compilation.
176183

177-
178184
**config.js**
179185

180-
``` javascript
186+
```javascript
181187
output: {
182-
path: "/home/proj/public/assets",
183-
publicPath: "/assets/"
188+
path: "/home/proj/public/assets",
189+
publicPath: "/assets/"
184190
}
185191
```
186192

187193
**index.html**
188-
``` html
194+
195+
```html
189196
<head>
190197
<link href="/assets/spinner.gif"/>
191198
</head>
192199
```
200+
193201
And a more complicated example of using a CDN and hashes for assets.
194202

195203
**config.js**
196204

197-
``` javascript
205+
```javascript
198206
output: {
199-
path: "/home/proj/cdn/assets/[hash]",
200-
publicPath: "http://cdn.example.com/assets/[hash]/"
207+
path: "/home/proj/cdn/assets/[hash]",
208+
publicPath: "http://cdn.example.com/assets/[hash]/"
201209
}
202210
```
203211

204212
**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.
205213

206-
``` javascript
214+
```javascript
207215
__webpack_public_path__ = myRuntimePublicPath
208216

209217
// rest of your application entry
210218
```
211219

212-
### `output.sourceMapFilename`
220+
## `output.sourceMapFilename`
213221

214222
The filename of the SourceMaps for the JavaScript files. They are inside the `output.path` directory.
215223

0 commit comments

Comments
 (0)