├── .gitignore ├── .vscode └── launch.json ├── README.V1.md ├── README.md ├── package.json ├── spec ├── end_to_end.spec.js ├── fixtures │ ├── a-file │ ├── app.css │ ├── assets │ │ ├── foo.css │ │ ├── foo.js │ │ ├── foo.min.css │ │ └── foo.min.js │ ├── entry.js │ └── node_modules │ │ ├── bad-package │ │ └── package.json │ │ ├── bootstrap │ │ ├── dist │ │ │ └── css │ │ │ │ └── bootstrap.min.css │ │ └── package.json │ │ ├── fake-a-package │ │ ├── fake-a-bundle.js │ │ ├── fake-a-entry.js │ │ └── package.json │ │ ├── fake-b-package │ │ ├── fake-b-bundle.js │ │ ├── fake-b-entry.js │ │ └── package.json │ │ ├── fake-c-package │ │ ├── fake-c-bundle.js │ │ ├── fake-c-entry.js │ │ └── package.json │ │ ├── fake-other-package │ │ ├── fake-other-bundle.js │ │ └── package.json │ │ ├── no-version │ │ └── package.json │ │ └── the-package │ │ └── package.json ├── option_validation.spec.js └── support │ └── jasmine.json ├── src └── index.js └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | **.DS_store 2 | node_modules 3 | .idea 4 | dist 5 | !spec/fixtures/node_modules 6 | !spec/fixtures/node_modules/**/dist -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Yarn Test", 11 | "program": "${workspaceFolder}/node_modules/.bin/jasmine" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /README.V1.md: -------------------------------------------------------------------------------- 1 | Deploy Assets extension for the HTML Webpack Plugin 2 | ======================================== 3 | 4 | Enhances [html-webpack-plugin](https://github.com/ampedandwired/html-webpack-plugin) 5 | functionality by allowing you to specify js or css assets from node_modules to be copied and included. 6 | 7 | ----- 8 | 9 | This is the **old version** of this plugin. Please update to the `2.x` [version](https://github.com/jharris4/html-webpack-deploy-plugin/blob/master/README.md) if possible. 10 | 11 | ----- 12 | 13 | Installation 14 | ------------ 15 | You must be running webpack on node 0.12.x or higher 16 | 17 | Install the plugin with npm: 18 | ```shell 19 | $ npm install --save-dev html-webpack-deploy-assets-plugin 20 | ``` 21 | 22 | (Note that this plugin was **renamed** in version `2.x`) 23 | 24 | Options 25 | ------- 26 | The available options are: 27 | 28 | - `packagePath`: `string` 29 | 30 | The path to installed packages, relative to the current directory. Default is `node_modules`. 31 | 32 | - `append`: `boolean` 33 | 34 | Specifies whether the assets will be appended (`true`) or prepended (`false`) to the list of assets in the html file. Default is `false`. 35 | 36 | - `publicPath`: `boolean` or `string` 37 | 38 | Specifying whether the assets should be prepended with webpack's public path or a custom publicPath (`string`). 39 | 40 | A value of `false` may be used to disable prefixing with webpack's publicPath, or a value like `myPublicPath/` may be used to prefix all assets with the given string. Default is `true`. 41 | 42 | - `outputPath`: `string` 43 | 44 | A directory name that will be created for each of the deployed assets. 45 | 46 | Instances of `[name]` will be replaced with the package name. 47 | Instances of `[version]` will be replaced with the package version. 48 | 49 | Default is `[name]-[version]`. 50 | 51 | - `packages`: `object` 52 | 53 | Specifies the definition of the assets from installed packages to be deployed. Defaults is `{}`. 54 | 55 | The keys/properties of the packages option must be the name of an installed package, and the definition must be 56 | an object with the following properties: 57 | 58 | - 'outputPath': `string` 59 | 60 | Allows the global `outputPath` to be overriden on a per-package basis. Default is the global value. 61 | 62 | - `assets`: `object` 63 | 64 | Specifies files or directories to be copied from the package's directory. 65 | 66 | The keys/properies are the asset to be copied, and the values are the target asset location within webpack's output directory. 67 | 68 | These are used as the from & to properties for the internal usage of the [copy-webpack-plugin](https://github.com/kevlened/copy-webpack-plugin) 69 | 70 | - `entries`: `array` 71 | 72 | Specifies files to be included in the html file. 73 | 74 | The file paths should be relative to webpack's output directory. 75 | 76 | - `assets`: `object` 77 | 78 | Specifies the definition of the local assets to be deployed. Defaults is `{}`. 79 | 80 | The keys/properies are the asset to be copied, and the values are the target asset location within webpack's output directory. 81 | 82 | - `links`: `array` 83 | 84 | Specifies the definition of the links to be deployed. Defaults is `[]`. 85 | 86 | The objects in the links are of the shape: 87 | 88 | ```javascript 89 | { 90 | href: "path/to/asset", // required - must be a string 91 | rel: "icon", // required - must be a string 92 | sizes: '16x16', // example of optional extra attribute 93 | anyOtherAttribute: 'value' 94 | } 95 | ``` 96 | 97 | For which the following would be injected into the html header: 98 | 99 | ```html 100 |
101 | 102 | 103 | ``` 104 | 105 | 106 | Example 107 | ------- 108 | Deploying bootstrap css and fonts and an assets directory from local files: 109 | 110 | ```javascript 111 | plugins: [ 112 | new HtmlWebpackPlugin(), 113 | new HtmlWebpackDeployAssetsPlugin({ 114 | "packages": { 115 | "bootstrap": { 116 | "assets": { 117 | "dist/css": "css/", 118 | "dist/fonts": "fonts/" 119 | }, 120 | "entries": [ 121 | "css/bootstrap.min.css", 122 | "css/bootstrap-theme.min.css" 123 | ] 124 | } 125 | }, 126 | "assets": { 127 | "src/assets": "assets/" 128 | } 129 | "link": [ 130 | { 131 | "href": "/assets/icon.png", 132 | "rel": "icon" 133 | } 134 | ] 135 | }) 136 | ] 137 | ``` 138 | 139 | This will generate a `dist/index.html` with your webpack bundled output **and** the following: 140 | 141 | ```html 142 | 143 | 144 | 145 | 146 |235 | ``` 236 | 237 | --- 238 | 239 | The **`packages`** option can be used to specify package assets that should be copied to the webpack output directory and injected into the `index.html` as tags. 240 | 241 | This option requires an object with any of the `copy`, `links`, or `scripts` properties. 242 | 243 | The settings for these are based on the [copy-webpack-plugin](https://github.com/webpack-contrib/copy-webpack-plugin) and the [html-webpack-tags-plugin](https://github.com/jharris4/html-webpack-tags-plugin) 244 | 245 | For example, to copy some assets from `bootstrap` to webpack, and insert a `` and ` 279 | 280 | ``` 281 | 282 | 283 | --- 284 | 285 | Examples 286 | ------- 287 | Deploying `Bootstrap` css and fonts and an assets directory from local files: 288 | 289 | ```javascript 290 | plugins: [ 291 | new HtmlWebpackPlugin(), 292 | new HtmlWebpackDeployAssetsPlugin({ 293 | packages: { 294 | 'bootstrap': { 295 | copy: [ 296 | { from: 'dist/css', to: 'css/' }, 297 | { from: 'dist/fonts', to: 'fonts/' } 298 | ], 299 | links: [ 300 | 'css/bootstrap.min.css', 301 | 'css/bootstrap-theme.min.css' 302 | ] 303 | } 304 | }, 305 | assets: { 306 | copy: [{ from: 'src/assets', to: 'assets/' }], 307 | links: { 308 | path: '/assets/icon.png', 309 | attributes: { 310 | rel:'icon' 311 | } 312 | } 313 | } 314 | }) 315 | ] 316 | ``` 317 | 318 | This will generate a `index.html` something like: 319 | 320 | ```html 321 | 322 | 323 |
324 | 325 |
326 | 327 | 328 | 329 | 330 | 331 |
334 |