|
| 1 | + |
| 2 | +# html-inline-source-webpack-plugin |
| 3 | + |
| 4 | +> 🔧A webpack plugin to inline source in html, wrapper of inline-source. |
| 5 | +
|
| 6 | +## Install |
| 7 | + |
| 8 | +```shell |
| 9 | +$ npm install html-inline-source-webpack-plugin --save-dev |
| 10 | +``` |
| 11 | + |
| 12 | +## Usage |
| 13 | + |
| 14 | +#### webpack.config.js |
| 15 | + |
| 16 | +```js |
| 17 | +// webpack.config.js |
| 18 | +let HtmlInlineSourceWebpackPlugin = require('html-inline-source-webpack-plugin'); |
| 19 | + |
| 20 | +module.exports = { |
| 21 | + /* Your config */ |
| 22 | + plugins : [ |
| 23 | + /* ... */ |
| 24 | + new HtmlInlineSourceWebpackPlugin(), |
| 25 | + ], |
| 26 | +}; |
| 27 | +``` |
| 28 | + |
| 29 | +#### index.html |
| 30 | +``` |
| 31 | +<!DOCTYPE html> |
| 32 | +<html> |
| 33 | +<head> |
| 34 | + <title> index </title> |
| 35 | + <link inline href="css/index.css" rel="stylesheet"> |
| 36 | +</head> |
| 37 | +<body> |
| 38 | + <script inline src="js/index.js" charset="utf-8"></script> |
| 39 | +</body> |
| 40 | +</html> |
| 41 | +``` |
| 42 | + |
| 43 | +## Notice |
| 44 | + |
| 45 | +``` |
| 46 | +<script inline src="js/index.js" charset="utf-8"></script> |
| 47 | +``` |
| 48 | + |
| 49 | +* Use `inline` attribute to inline source; |
| 50 | +* Ensure `src` or `href` is linked to a correct file. |
| 51 | + |
| 52 | +## Options |
| 53 | + |
| 54 | +#### Default option |
| 55 | + |
| 56 | +```js |
| 57 | +new HtmlInlineSourceWebpackPlugin() |
| 58 | +``` |
| 59 | + |
| 60 | +#### Custom option |
| 61 | + |
| 62 | +This option would apply to all files. |
| 63 | + |
| 64 | +```js |
| 65 | +new HtmlInlineSourceWebpackPlugin({ |
| 66 | + option : { |
| 67 | + compress : false, |
| 68 | + rootpath : path.resolve('./dist'), |
| 69 | + }, |
| 70 | +}) |
| 71 | +``` |
| 72 | + |
| 73 | +#### Custom option for different file |
| 74 | + |
| 75 | +Use `test` to let different option apply to different files. |
| 76 | + |
| 77 | +```js |
| 78 | +new HtmlInlineSourceWebpackPlugin([ |
| 79 | + { |
| 80 | + test : /\bindex\.html$/, |
| 81 | + option : { |
| 82 | + ignore : 'script', |
| 83 | + rootpath : path.resolve('./dist'), |
| 84 | + }, |
| 85 | + }, |
| 86 | + { |
| 87 | + test : /\bexample\.html$/, |
| 88 | + option : { |
| 89 | + ignore : 'css', |
| 90 | + rootpath : path.resolve('./dist'), |
| 91 | + }, |
| 92 | + }, |
| 93 | + { |
| 94 | + /* This option would apply to the rest files */ |
| 95 | + option : { |
| 96 | + ignore : ['script', 'css'], |
| 97 | + rootpath : path.resolve('./dist'), |
| 98 | + }, |
| 99 | + }, |
| 100 | +]) |
| 101 | +``` |
| 102 | + |
| 103 | +#### More option |
| 104 | + |
| 105 | +see [here](https://github.com/popeindustries/inline-source#usage). |
| 106 | + |
| 107 | +## Related |
| 108 | + |
| 109 | +* [inline-source](https://www.npmjs.com/package/inline-source) |
| 110 | + * A plugin to inline source in html. You have to inline source after webpack manually. |
| 111 | +* [html-webpack-inline-source-plugin](https://www.npmjs.com/package/html-webpack-inline-source-plugin) |
| 112 | + * Depends `html-webpack-plugin`, only inline source in `head` or `body`. |
| 113 | +* [html-inject-webpack-plugin](https://www.npmjs.com/package/html-inject-webpack-plugin) |
| 114 | + * You have to define flag name in html. Only inline source which is in your `src` directory. |
| 115 | +* [inline-resource-plugin](https://www.npmjs.com/package/inline-resource-plugin) |
| 116 | + * Only inline source which is in your `src` directory. |
| 117 | + |
| 118 | +## License |
| 119 | + |
| 120 | +MIT |
0 commit comments