🔧A webpack plugin to inline source in html, wrapper of inline-source.
- Node - v4.7.0
- npm - 2.15.11
- webpack - ^1.14.0
$ npm install --save-dev html-inline-source-webpack-plugin
// webpack.config.js
let HtmlInlineSourceWebpackPlugin = require('html-inline-source-webpack-plugin');
module.exports = {
/* Your config */
plugins : [
/* ... */
new HtmlInlineSourceWebpackPlugin(),
],
};
<!DOCTYPE html>
<html>
<head>
<title> index </title>
<link inline href="css/index.css" rel="stylesheet">
</head>
<body>
<script inline src="js/index.js" charset="utf-8"></script>
</body>
</html>
<script inline src="js/index.js" charset="utf-8"></script>
- Use
inline
attribute to inline source; - Ensure
src
orhref
is linked to a correct file.
new HtmlInlineSourceWebpackPlugin()
This option would apply to all files.
new HtmlInlineSourceWebpackPlugin({
option : {
compress : false,
rootpath : path.resolve('./dist'),
},
})
Use test
to let different option apply to different files.
new HtmlInlineSourceWebpackPlugin([
{
test : /\bindex\.html$/,
option : {
ignore : 'script',
rootpath : path.resolve('./dist'),
},
},
{
test : /\bexample\.html$/,
option : {
ignore : 'css',
rootpath : path.resolve('./dist'),
},
},
{
/* This option would apply to the rest files */
option : {
ignore : ['script', 'css'],
rootpath : path.resolve('./dist'),
},
},
])
see here.
new HtmlInlineSourceWebpackPlugin(function () {
console.log('inline source done!');
})
/* or */
new HtmlInlineSourceWebpackPlugin({
/* option */
}, function () {
console.log('inline source done!');
})
- inline-source
- A plugin to inline source in html. You have to inline source after webpack manually.
- html-webpack-inline-source-plugin
- Depends
html-webpack-plugin
, only inline source inhead
orbody
.
- Depends
- html-inject-webpack-plugin
- You have to define flag name in html. Only inline source which is in your
src
directory.
- You have to define flag name in html. Only inline source which is in your
- inline-resource-plugin
- Only inline source which is in your
src
directory.
- Only inline source which is in your
MIT