html-elements-webpack-plugin
This repository holds the JavaScript source code and distributable bundle of html-elements-webpack-plugin
, the webpack plugin to append head elements during the creation of index.html
with the source code is copied from AngularClass/angular2-webpack-starter.
It can be considered as a shorthand implementation the html-elements-webpack-plugin
developed by AngularClass.
Getting started
Installation
You can install html-elements-webpack-plugin
using npm
npm install html-elements-webpack-plugin --save
Usage
Create a JS file (ex: head-config.js) in your ./config
folder, and define head elements you want them to be appended during the creation of index.html
:
head-config.js
module.exports = {
link: [
{ rel: 'apple-touch-icon', sizes: '57x57', href: '/assets/icon/apple-icon-57x57.png' },
{ rel: 'apple-touch-icon', sizes: '60x60', href: '/assets/icon/apple-icon-60x60.png' },
{ rel: 'apple-touch-icon', sizes: '72x72', href: '/assets/icon/apple-icon-72x72.png' },
{ rel: 'apple-touch-icon', sizes: '76x76', href: '/assets/icon/apple-icon-76x76.png' },
{ rel: 'apple-touch-icon', sizes: '114x114', href: '/assets/icon/apple-icon-114x114.png' },
{ rel: 'apple-touch-icon', sizes: '120x120', href: '/assets/icon/apple-icon-120x120.png' },
{ rel: 'apple-touch-icon', sizes: '144x144', href: '/assets/icon/apple-icon-144x144.png' },
{ rel: 'apple-touch-icon', sizes: '152x152', href: '/assets/icon/apple-icon-152x152.png' },
{ rel: 'apple-touch-icon', sizes: '180x180', href: '/assets/icon/apple-icon-180x180.png' },
{ rel: 'icon', type: 'image/png', sizes: '192x192', href: '/assets/icon/android-icon-192x192.png' },
{ rel: 'icon', type: 'image/png', sizes: '32x32', href: '/assets/icon/favicon-32x32.png' },
{ rel: 'icon', type: 'image/png', sizes: '96x96', href: '/assets/icon/favicon-96x96.png' },
{ rel: 'icon', type: 'image/png', sizes: '16x16', href: '/assets/icon/favicon-16x16.png' },
{ rel: 'manifest', href: '/assets/manifest.json' }
],
meta: [
{ name: 'msapplication-TileColor', content: '#00bcd4' },
{ name: 'msapplication-TileImage', content: '/assets/icon/ms-icon-144x144.png', '=content': true },
{ name: 'theme-color', content: '#00bcd4' }
]
};
webpack.config.js
const HtmlElementsWebpackPlugin = require('html-elements-webpack-plugin');
module.exports = {
plugins: [
...
new HtmlElementsWebpackPlugin({
headTags: require('./head-config')
}),
...
]
};
index.html
<!DOCTYPE html>
<head>
<base href="/">
<meta charset="utf-8" />
<title></title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1" name="viewport" />
<% if (webpackConfig.htmlElements.headTags) { %>
<%= webpackConfig.htmlElements.headTags %>
<% } %>
</head>
<body>
<main>Loading...</main>
</body>
</html>
Awesome! html-elements-webpack-plugin
will now append the head elements specified in head-config.js
during the creation of index.html
:
Licence
The MIT License (MIT)
Copyright (c) 2016 Burak Tasci