Skip to content

Commit f0b140a

Browse files
committed
docs(guides): mention complex entry point configuration in author-libraries
Note that `entry` arrays are not recommended, provide a way to properly expose stylesheets, and add a link to an `entry` object example.
1 parent 4d82b1c commit f0b140a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/content/guides/author-libraries.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ __src/ref.json__
6161

6262
__src/index.js__
6363

64-
```javascript
64+
``` js
6565
import _ from 'lodash';
6666
import numRef from './ref.json';
6767

@@ -80,7 +80,7 @@ export function wordToNum(word) {
8080

8181
The usage specification for the library use will be as follows:
8282

83-
```javascript
83+
``` js
8484
// ES2015 module import
8585
import * as webpackNumbers from 'webpack-numbers';
8686
// CommonJS module require
@@ -142,7 +142,7 @@ We can start with this basic webpack configuration:
142142

143143
__webpack.config.js__
144144

145-
```javascript
145+
``` js
146146
var path = require('path');
147147

148148
module.exports = {
@@ -240,6 +240,8 @@ __webpack.config.js__
240240
};
241241
```
242242

243+
T> Note that the `library` setup is tied to the `entry` configuration. For most libraries, specifying a single entry point is sufficient. While [multi-part libraries](https://github.com/webpack/webpack/tree/master/examples/multi-part-library) are possible, it is simpler to expose partial exports through an [index script](https://stackoverflow.com/questions/34072598/es6-exporting-importing-in-index-file) that serves as a single entry point. Using an `array` as an `entry` point for a library is __not recommended__.
244+
243245
This exposes your library bundle available as a global variable named `webpackNumbers` when imported. To make the library compatible with other environments, add `libraryTarget` property to the config. This will add the different options about how the library can be exposed.
244246

245247
__webpack.config.js__
@@ -305,6 +307,8 @@ Or, to add as standard module as per [this guide](https://github.com/dherman/def
305307

306308
The key `main` refers to the [standard from `package.json`](https://docs.npmjs.com/files/package.json#main), and `module` to [a](https://github.com/dherman/defense-of-dot-js/blob/master/proposal.md) [proposal](https://github.com/rollup/rollup/wiki/pkg.module) to allow the JavaScript ecosystem upgrade to use ES2015 modules without breaking backwards compatibility.
307309

308-
W> `module` will point to a module that has ES2015 module syntax but otherwise only syntax features that browser/node supports.
310+
W> The `module` property should point to a script that utilizes ES2015 module syntax but no other syntax features that aren't yet supported by browsers or node. This enables
309311

310312
Now you can [publish it as an npm package](https://docs.npmjs.com/getting-started/publishing-npm-packages) and find it at [unpkg.com](https://unpkg.com/#/) to distribute it to your users.
313+
314+
T> To expose stylesheets associated with your library, the [`ExtractTextPlugin`](/plugins/extract-text-webpack-plugin) should be used. Users can then consume and load these as they would any other stylesheet.

0 commit comments

Comments
 (0)