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
{{ message }}
This repository was archived by the owner on Apr 5, 2021. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+44-1
Original file line number
Diff line number
Diff line change
@@ -43,14 +43,17 @@ The constructor takes a configuration object with the following properties.
43
43
| --- | --- | --- | --- |
44
44
|`externals`| array<object>| An array of vendor modules that will be excluded from your Webpack bundle and added as `script` or `link` tags in your HTML output. |*None*|
45
45
|`externals[].module`| string | The name of the vendor module. This should match the package name, e.g. if you are writing `import React from 'react'`, this would be `react`. |*None*|
46
-
|`externals[].entry`| string \| array<string>\| object \| array<object \| string>| The path, relative to the vendor module directory, to its pre-bundled distro file. e.g. for React, use `dist/react.js`, since the file exists at `node_modules/react/dist/react.js`. Specify an array if there are multiple CSS/JS files to inject. To use a CDN instead, simply use a fully qualified URL beginning with `http://`, `https://`, or `//`.<br><br>For entries whose type (JS or CSS) cannot be inferred by file extension, pass an object such as `{ path: 'https://some/url', type: 'css' }` (or `type: 'js'`). |*None*|
46
+
|`externals[].dist`| string | The relative path of the vendor distribution directory. All entry paths are resolved relative to this directory, but it is *not* included in the output path. |*None*|
47
+
|`externals[].entry`| string \| array<string>\| object \| array<object \| string>| The path, relative to the vendor distribution directory, to its pre-bundled distro file. e.g. for React, use `dist/react.js` (or, if you have set `.dist: "dist"`, just use `react.js`), since the file exists at `node_modules/react/dist/react.js`. Specify an array if there are multiple CSS/JS files to inject. To use a CDN instead, simply use a fully qualified URL beginning with `http://`, `https://`, or `//`.<br><br>For entries whose type (JS or CSS) cannot be inferred by file extension, pass an object such as `{ path: 'https://some/url', type: 'css' }` (or `type: 'js'`). |*None*|
47
48
|`externals[].entry.path`| string | If entry is an object, the path to the asset. |*None*|
49
+
|`externals[].entry.dist`| string | The path of the vendor distribution directory, for this entry alone. |*Inherits from `externals[].dist`*|
48
50
|`externals[].entry.type`|`'js'`\|`'css'`| The asset type, if it cannot be inferred. |*Inferred by extension when possible*|
49
51
|`externals[].entry`<br>` .cwpPatternConfig`| object | The properties to set on the [`copy-webpack-plugin` pattern object](https://github.com/webpack-contrib/copy-webpack-plugin#patterns). This object is merged in with the default `from` and `to` properties which are generated by the externals plugin. |`{}`|
50
52
|`externals[].entry`<br>` .attributes`| object.<string,string>| Additional attributes to add to the injected tag. |`{}`|
51
53
|`externals[].global`| string \| null | For JavaScript modules, this is the name of the object globally exported by the vendor's dist file. e.g. for React, use `React`, since `react.js` creates a `window.React` global. For modules without an export (such as CSS), omit this property or use `null`. |`null`|
52
54
|`externals[].supplements`| array<string>\| array<object>| For modules that require additional resources, specify globs of files to copy over to the output. e.g. for Bootstrap CSS, use `['dist/fonts/']`, since Glyphicon fonts are referenced in the CSS and exist at `node_modules/bootstrap/dist/fonts/`. Supplements can be specified as just an array of paths, or an array of objects with a path and copy plugin pattern object. |`[]`|
53
55
|`externals[].supplements[]`<br>` .path`| string | The glob path to copy assets from. |*None*|
56
+
|`externals[].supplements[]`<br>` .dist`| string | The path of the vendor distribution directory, for this entry alone. |*Inherits from `externals[].dist`*|
54
57
|`externals[].supplements[]`<br>` .cwpPatternConfig`| object | The properties to set on the [`copy-webpack-plugin` pattern object](https://github.com/webpack-contrib/copy-webpack-plugin#patterns). This object is merged in with the default `from` and `to` properties which are generated by the externals plugin. |`{}`|
55
58
|`externals[].append`| boolean | Set to true to inject this module after your Webpack bundles. |`false`|
56
59
|`hash`| boolean | Set to true to append the injected module distro paths with a unique hash for cache-busting. |`false`|
@@ -250,6 +253,46 @@ new HtmlWebpackExternalsPlugin({
250
253
})
251
254
```
252
255
256
+
### Omitting distribution path example
257
+
258
+
By default, the Webpack output directory includes the full relative path of all copied files relative to their module root, including top-level directories like `dist` or `build`. You can omit these top-level directories in your output.
259
+
260
+
Do not include a trailing slash or leading slash in the distribution path, they are concatenated automatically by the plugin.
261
+
262
+
This example assumes `bootstrap` is installed in the app. It:
263
+
264
+
1. copies `node_modules/bootstrap/dist/css/bootstrap.min.css` to `<output path>/vendor/bootstrap/css/bootstrap.min.css`
265
+
1. copies `node_modules/bootstrap/dist/css/bootstrap-theme.min.css` to `<output path>/vendor/bootstrap/bootstrap-theme.min.css`
266
+
1. copies all contents of `node_modules/bootstrap/dist/fonts/` to `<output path>/vendor/bootstrap/fonts/`
267
+
1. copies `node_modules/bootstrap/js/dist/dropdown.js` to `<output path>/vendor/bootstrap/dropdown.js`
268
+
1. adds `<link href="<public path>/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">` to your HTML file, before your chunks
269
+
1. adds `<link href="<public path>/vendor/bootstrap/bootstrap-theme.min.css" rel="stylesheet">` to your HTML file, before your chunks
270
+
271
+
```js
272
+
newHtmlWebpackExternalsPlugin({
273
+
externals: [
274
+
{
275
+
module:'bootstrap',
276
+
dist:'dist',
277
+
entry: [
278
+
'css/bootstrap.min.css',
279
+
{
280
+
dist:'dist/css',
281
+
path:'bootstrap-theme.min.css',
282
+
},
283
+
],
284
+
supplements: [
285
+
'fonts/',
286
+
{
287
+
dist:'js/dist',
288
+
path:'dropdown.js',
289
+
},
290
+
],
291
+
},
292
+
],
293
+
})
294
+
```
295
+
253
296
### Customizing public path example
254
297
255
298
By default, local externals are resolved from the same root path as your Webpack configuration file's `output.publicPath`, concatenated with the `outputPath` variable. This is configurable.
0 commit comments