Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(output): library names for UMD since 3.1.0 #1389

Merged
merged 2 commits into from
Jul 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 23 additions & 9 deletions content/configuration/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ If using the [`output.library`](#output-library) option, the library name is aut

`string`

`string` or `object` (since webpack 3.1.0; for `libraryTarget: "umd"`)

Use `library`, and `libraryTarget` below, when writing a JavaScript library that should export values, which can be used by other code depending on it. Pass a string with the name of the library:

``` js
Expand All @@ -303,7 +305,7 @@ The name is used depending on the value of the [`output.libraryTarget`](#output-

Note that `output.libraryTarget` defaults to `var`. This means if only `output.library` is used it is exported as variable declaration (when used as script tag it's available in the global scope after execution).

T> Read the [authoring libraries guide](/guides/author-libraries) guide for more information on `output.library` as well as `ouput.libraryTarget`.
T> Read the [authoring libraries guide](/guides/author-libraries) guide for more information on `output.library` as well as `output.libraryTarget`.


## `output.libraryExport`
Expand Down Expand Up @@ -417,7 +419,6 @@ require(['MyLibrary'], function(MyLibrary) {
});
```


`libraryTarget: "umd"` - This is a way for your library to work with all the module definitions (and where aren't modules at all). It will work with CommonJS, AMD and as global variable. Take a look at the [UMD Repository](https://github.com/umdjs/umd) to learn more.

In this case, you need the `library` property to name your module:
Expand Down Expand Up @@ -446,22 +447,35 @@ And finally the output is:
});
```

Since webpack 3.1.0, you may specify an object for `library` for differing names per targets:

```javascript
output: {
library: {
root: "MyLibrary",
amd: "my-library",
commonjs: "my-common-library"
},
libraryTarget: "umd"
}
```

Module proof library.


`libraryTarget: "assign"` - Here webpack will blindly generate an implied global.

```javascript
MyLibrary = _entry_return_;
```
Be aware that if `MyLibrary` isn't defined earlier your library will be set in global scope.
``` javascript
MyLibrary = _entry_return_;
```

Be aware that if `MyLibrary` isn't defined earlier your library will be set in global scope.

`libraryTarget: "jsonp"` - This will wrap the return value of your entry point into a jsonp wrapper.

```javascript
MyLibrary(_entry_return_);
```
``` javascript
MyLibrary(_entry_return_);
```

The dependencies for your library will be defined by the [`externals`](/configuration/externals/) config.

Expand Down