|
| 1 | +# Webpack WAR plugin |
| 2 | +[](https://travis-ci.org/DevWurm/webpack-war-plugin) |
| 3 | +[](https://coveralls.io/github/DevWurm/webpack-war-plugin?branch=master) |
| 4 | + |
| 5 | +This is a [Webpack](https://webpack.github.io/) plugin which simplifies and automates the creation of a [Web Application Archive (WAR)](https://en.wikipedia.org/wiki/WAR_(file_format)) from your Webpack build outputs and other project files. This can be useful if you want to deploy your static / Single Page Web App or your applications web frontend to a Java (EE) Application server. |
| 6 | + |
| 7 | +## Installation |
| 8 | +You can install the plugin via yarn |
| 9 | +```bash |
| 10 | +yarn add --dev webpack-war-plugin |
| 11 | +``` |
| 12 | +or via npm |
| 13 | +```bash |
| 14 | +npm install --dev webpack-war-plugin |
| 15 | +``` |
| 16 | + |
| 17 | +## Usage |
| 18 | +### Basic Usage |
| 19 | +To add the webpack-war-plugin to your build just add an instance of `WebpackWarPlugin` to the `plugins` section of your Webpack configuration |
| 20 | +```javascript |
| 21 | +const { WebpackWarPlugin } = require('webpack-war-plugin'); |
| 22 | + |
| 23 | +module.exports = { |
| 24 | + ..., |
| 25 | + plugins: [ |
| 26 | + new WebpackWarPlugin(), |
| 27 | + ... |
| 28 | + ], |
| 29 | + ... |
| 30 | +}; |
| 31 | +``` |
| 32 | +By default an archive containing all emitted Webpack build outputs is generated in the output directory of your Webpack build. It is named like your project. |
| 33 | + |
| 34 | +### Configuration |
| 35 | +You can influence the generated archive by supplying a configuration object of the following structure to the plugins constructor: |
| 36 | +```typescript |
| 37 | +type WebpackWarPluginOptions = { |
| 38 | + archiveName?: string; |
| 39 | + webInf?: string; |
| 40 | + additionalElements?: { |
| 41 | + path: string; |
| 42 | + destPath?: string; |
| 43 | + }[]; |
| 44 | +}; |
| 45 | +``` |
| 46 | +| Option | Effect | |
| 47 | +| --- | --- | |
| 48 | +| `archiveName` *[optional]* | Sets the output name of the archive | |
| 49 | +| `webInf` *[optional]* | Specifies a path to a directory (or file) which will be included into the archive with the path `WEB-INF` | |
| 50 | +| `additionalElements` *[optional]* | Specifies multiple files or directories, which will be included in the archive. Each entry is a object with the following properties: `path` (The path of the source element), `destPath` (*[optional]* The path of the specified file / directory inside of the archive [by default `path` is used]) | |
| 51 | + |
| 52 | +### Example |
| 53 | +The following plugin configuration: |
| 54 | +```javascript |
| 55 | +const { WebpackWarPlugin } = require('webpack-war-plugin'); |
| 56 | + |
| 57 | +module.exports = { |
| 58 | + entry: { |
| 59 | + file1: './src/file1.js' |
| 60 | + }, |
| 61 | + ..., |
| 62 | + plugins: [ |
| 63 | + new WebpackWarPlugin({ |
| 64 | + archiveName: 'archive', |
| 65 | + webInf: './web-inf', |
| 66 | + additionalElemens: [ |
| 67 | + { path: 'context/context.xml', destPath: 'META-INF/context.xml'}, |
| 68 | + { path: 'package.json' }, |
| 69 | + { path: 'images', destPath: 'assets/images' } |
| 70 | + ] |
| 71 | + }), |
| 72 | + ... |
| 73 | + ], |
| 74 | + ... |
| 75 | +}; |
| 76 | + |
| 77 | +``` |
| 78 | +generates an archive with the name `archive.war` in the Webpack output directory with the following structure: |
| 79 | +``` |
| 80 | +archive.war |
| 81 | +| |
| 82 | +|\_ file1.js |
| 83 | +| |
| 84 | +|\_ WEB-INF |
| 85 | +| \_ web.xml |
| 86 | +| |
| 87 | +|\_ META-INF |
| 88 | +| \_ context.xml |
| 89 | +| |
| 90 | +|\_ package.json |
| 91 | +| |
| 92 | + \_ assets |
| 93 | + \_ images |
| 94 | + \_ img.png |
| 95 | +``` |
| 96 | + |
| 97 | +## Development |
| 98 | +### Typescript |
| 99 | +The plugin is built with [Typescript](http://www.typescriptlang.org/) and the resulting package contains the corresponding typings. |
| 100 | + |
| 101 | +### Building |
| 102 | +After checking out the project you can build transpile the Typescript via |
| 103 | +```bash |
| 104 | +yarn run build |
| 105 | +``` |
| 106 | +The build output is stored in `dist`. |
| 107 | + |
| 108 | +### Testing |
| 109 | +#### Unit tests |
| 110 | +Unit tests are named `[tested-component].spec.ts`.<br> |
| 111 | +They can be run via [Mocha](https://mochajs.org/) with |
| 112 | +```bash |
| 113 | +yarn run test |
| 114 | +``` |
| 115 | +Test coverage is measured via [nyc](https://github.com/istanbuljs/nyc) and can be triggered with |
| 116 | +```bash |
| 117 | +yarn run test:coverage |
| 118 | +``` |
| 119 | + |
| 120 | +#### Functional tests |
| 121 | +Functional test fixtures are located in `functional_tests`. |
| 122 | +To set up all fixtures run |
| 123 | +```bash |
| 124 | +yarn run test:functional:setup |
| 125 | +``` |
| 126 | +To execute the tests via Mocha run |
| 127 | +```bash |
| 128 | +yarn run test:functional |
| 129 | +``` |
| 130 | + |
| 131 | +### Continuous integration |
| 132 | +Continious integration is realized via [Travis-CI](https://travis-ci.org/DevWurm/webpack-war-plugin). Coverage reports are shown on [Coveralls](https://coveralls.io/github/DevWurm/webpack-war-plugin). Deployments to NPM are automatically triggered via Git tags. |
| 133 | + |
| 134 | +## Licensing |
| 135 | +The app is distributed under the MIT License (read [`LICENSE`](LICENSE) for more information). |
| 136 | +Copyright (c) 2017 Leo Lindhorst |
| 137 | + |
| 138 | +## Collaborating |
| 139 | +I really appreciate any kind of collaboration!<br> |
| 140 | +You can use the [GitHub issue tracker](https://github.com/DevWurm/webpack-war-plugin/issues) for bugs and feature requests or [create a pull request](https://github.com/DevWurm/webpack-war-plugin/pulls) to submit |
| 141 | +changes. |
| 142 | +If you don't want to use these possibilities, you can also write me an email to |
| 143 | +<a href='mailto:devwurm@devwurm.net'>devwurm@devwurm.net</a>. |
| 144 | + |
| 145 | +## Contact |
| 146 | +If you have any questions, ideas, etc. feel free to contact me:<br> |
| 147 | +DevWurm<br> |
| 148 | +Email: <a href='mailto:devwurm@devwurm.net'>devwurm@devwurm.net</a><br> |
| 149 | +Jabber: devwurm@conversations.im<br> |
| 150 | +Twitter: [@DevWurm](https://twitter.com/DevWurm)<br> |
0 commit comments