Skip to content

Commit 28aa7a8

Browse files
author
matt
committed
- update configuration index page with missing libraryTargets
- add documentation of missing libraryTargets to output documentation - slightly adjust inconsistencies
1 parent 1cb0598 commit 28aa7a8

File tree

2 files changed

+52
-9
lines changed

2 files changed

+52
-9
lines changed

content/configuration/index.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ contributors:
88
- bondz
99
- sricc
1010
- terinjokes
11+
- mattce
1112
---
1213

1314
webpack is fed via a configuration object. It is passed in one of two ways depending on how you are using webpack: through the terminal or via Node.js. All the available configuration options are specified below.
@@ -57,12 +58,18 @@ var path = require('path');
5758
[library](/configuration/output#output-library): "MyLibrary", // string,
5859
// the name of the exported library
5960
60-
<details><summary>[libraryTarget](/configuration/output#output-librarytarget): "umd", // enum</summary>
61-
[libraryTarget](/configuration/output#output-librarytarget): "commonjs2", // exported with module.exports
62-
[libraryTarget](/configuration/output#output-librarytarget): "commonjs", // exported as properties to exports
63-
[libraryTarget](/configuration/output#output-librarytarget): "amd", // defined with AMD defined method
64-
[libraryTarget](/configuration/output#output-librarytarget): "this", // property set on this
65-
[libraryTarget](/configuration/output#output-librarytarget): "var", // variable defined in root scope
61+
<details><summary>[libraryTarget](/configuration/output#output-librarytarget): "umd", // universal module definition</summary>
62+
[libraryTarget](/configuration/output#output-librarytarget): "umd2", // universal module definition
63+
[libraryTarget](/configuration/output#output-librarytarget): "commonjs2", // exported with module.exports
64+
[libraryTarget](/configuration/output#output-librarytarget): "commonjs-module", // exports with module.exports
65+
[libraryTarget](/configuration/output#output-librarytarget): "commonjs", // exported as properties to exports
66+
[libraryTarget](/configuration/output#output-librarytarget): "amd", // defined with AMD defined method
67+
[libraryTarget](/configuration/output#output-librarytarget): "this", // property set on this
68+
[libraryTarget](/configuration/output#output-librarytarget): "var", // variable defined in root scope
69+
[libraryTarget](/configuration/output#output-librarytarget): "assign", // blind assignment
70+
[libraryTarget](/configuration/output#output-librarytarget): "window", // property set to window object
71+
[libraryTarget](/configuration/output#output-librarytarget): "global", // property set to global object
72+
[libraryTarget](/configuration/output#output-librarytarget): "jsonp", // jsonp wrapper
6673
</details>
6774
// the type of the exported library
6875

content/configuration/output.md

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,27 @@ MyLibrary.doSomething(); //if this is window
250250
```
251251

252252

253-
`libraryTarget: "commonjs"` - When your library is loaded, the return value of your entry point will be part of the exports object. As the name implies, this is used in CommonJS environments:
253+
`libraryTarget: "window"` - When your library is loaded, **the return value of your entry point** will be part `window` object.
254+
255+
```javascript
256+
window["MyLibrary"] = _entry_return_;
257+
258+
//your users will use your library like:
259+
window.MyLibrary.doSomething();
260+
```
261+
262+
263+
`libraryTarget: "global"` - When your library is loaded, **the return value of your entry point** will be part `global` object.
264+
265+
```javascript
266+
global["MyLibrary"] = _entry_return_;
267+
268+
//your users will use your library like:
269+
global.MyLibrary.doSomething();
270+
```
271+
272+
273+
`libraryTarget: "commonjs"` - When your library is loaded, **the return value of your entry point** will be part of the exports object. As the name implies, this is used in CommonJS environments:
254274

255275
```javascript
256276
exports["MyLibrary"] = _entry_return_;
@@ -259,7 +279,8 @@ exports["MyLibrary"] = _entry_return_;
259279
require("MyLibrary").doSomething();
260280
```
261281

262-
`libraryTarget: "commonjs2"` - When your library is loaded, the return value of your entry point will be part of the exports object. As the name implies, this is used in CommonJS environments:
282+
283+
`libraryTarget: "commonjs2"` - When your library is loaded, **the return value of your entry point** will be part of the exports object. As the name implies, this is used in CommonJS environments:
263284

264285
```javascript
265286
module.exports = _entry_return_;
@@ -320,7 +341,7 @@ require(["MyLibrary"], function(MyLibrary){
320341
`libraryTarget: "umd"` - This is a way for your library to work with all the module definitions (and where aren't modules at all).
321342
It will work with CommonJS, AMD and as global variable. You can check the [UMD Repository](https://github.com/umdjs/umd) to know more about it.
322343

323-
In this case, you need the another property to name your module:
344+
In this case, you need the `library` property to name your module:
324345

325346
```javascript
326347
output: {
@@ -347,6 +368,21 @@ And finally the output is:
347368

348369
Module proof library.
349370

371+
372+
`libraryTarget: "assign"` - Here webpack will blindly generates an implied global.
373+
374+
```javascript
375+
MyLibrary = _entry_return_;
376+
```
377+
Be aware that if `MyLibrary` isn't defined earlier your library will be set in global scope.
378+
379+
380+
`libraryTarget: "jsonp"` - This will wrap the return value of your entry point into a jsonp wrapper.
381+
382+
```javascript
383+
MyLibrary( _entry_return_ );
384+
```
385+
350386
The dependencies for your library will be defined by the [`externals`](/configuration/externals/) config.
351387

352388

0 commit comments

Comments
 (0)