Skip to content

Commit

Permalink
feat(webpack): Better default template for html webpack plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
d4rkr00t committed Sep 18, 2016
1 parent e796543 commit 5efa428
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 36 deletions.
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ function aikDevServer(input, flags, console) {
* @param {String[]} input
* @param {Flags} flags
* @param {Object} console
*
* @return {Promise}
*/
function aikBuild(input, flags, console) {
var _input2 = _slicedToArray(input, 1);
Expand Down
13 changes: 4 additions & 9 deletions lib/webpack-config-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,10 @@ function setupOutput(filename) {
* @return {Array}
*/
function setupPlugins(template) {
var htmlPluginOptions = {
title: (0, _last2.default)(process.cwd().split(_path2.default.sep))
};

if (template) {
htmlPluginOptions.template = template;
}

return [new _webpack2.default.HotModuleReplacementPlugin(), new _htmlWebpackPlugin2.default(htmlPluginOptions), new _npmInstallWebpackPlugin2.default({
return [new _webpack2.default.HotModuleReplacementPlugin(), new _htmlWebpackPlugin2.default({
title: (0, _last2.default)(process.cwd().split(_path2.default.sep)),
template: template ? template : require.resolve('../template/index.ejs')
}), new _npmInstallWebpackPlugin2.default({
dev: true,
peerDependencies: true
}), new _webpack2.default.DefinePlugin({ 'process.env.NODE_ENV': '"development"' })];
Expand Down
13 changes: 4 additions & 9 deletions lib/webpack-config-prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,10 @@ function setupOutput(filename, dist, base) {
* @return {Array}
*/
function setupPlugins(template) {
var htmlPluginOptions = {
title: (0, _last2.default)(process.cwd().split(_path2.default.sep))
};

if (template) {
htmlPluginOptions.template = template;
}

return [new _htmlWebpackPlugin2.default(htmlPluginOptions), new _npmInstallWebpackPlugin2.default({
return [new _htmlWebpackPlugin2.default({
title: (0, _last2.default)(process.cwd().split(_path2.default.sep)),
template: template ? template : require.resolve('../template/index.ejs')
}), new _npmInstallWebpackPlugin2.default({
save: false,
saveDev: false,
saveExact: false
Expand Down
13 changes: 4 additions & 9 deletions src/lib/webpack-config-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,12 @@ export function setupOutput(filename) {
* @return {Array}
*/
export function setupPlugins(template) {
const htmlPluginOptions = {
title: last(process.cwd().split(path.sep))
};

if (template) {
htmlPluginOptions.template = template;
}

return [
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin(htmlPluginOptions),
new HtmlWebpackPlugin({
title: last(process.cwd().split(path.sep)),
template: template ? template : require.resolve('../template/index.ejs')
}),
new NpmInstallPlugin({
dev: true,
peerDependencies: true
Expand Down
13 changes: 4 additions & 9 deletions src/lib/webpack-config-prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,11 @@ export function setupOutput(filename, dist, base) {
* @return {Array}
*/
export function setupPlugins(template) {
const htmlPluginOptions = {
title: last(process.cwd().split(path.sep))
};

if (template) {
htmlPluginOptions.template = template;
}

return [
new HtmlWebpackPlugin(htmlPluginOptions),
new HtmlWebpackPlugin({
title: last(process.cwd().split(path.sep)),
template: template ? template : require.resolve('../template/index.ejs')
}),
new NpmInstallPlugin({
save: false,
saveDev: false,
Expand Down
11 changes: 11 additions & 0 deletions template/index.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<div id="app"></div>
</body>
</html>
10 changes: 10 additions & 0 deletions test/mocks/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>

</body>
</html>

0 comments on commit 5efa428

Please sign in to comment.