From 5efa428ec6b8c1253f857ab7f2a42ca770694ce3 Mon Sep 17 00:00:00 2001 From: Stanislav Sysoev Date: Sun, 18 Sep 2016 15:17:57 +0300 Subject: [PATCH] feat(webpack): Better default template for html webpack plugin --- lib/index.js | 2 ++ lib/webpack-config-dev.js | 13 ++++--------- lib/webpack-config-prod.js | 13 ++++--------- src/lib/webpack-config-dev.js | 13 ++++--------- src/lib/webpack-config-prod.js | 13 ++++--------- template/index.ejs | 11 +++++++++++ test/mocks/index.html | 10 ++++++++++ 7 files changed, 39 insertions(+), 36 deletions(-) create mode 100644 template/index.ejs create mode 100644 test/mocks/index.html diff --git a/lib/index.js b/lib/index.js index 6c904fc..b442cd9 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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); diff --git a/lib/webpack-config-dev.js b/lib/webpack-config-dev.js index 28de40a..de388d0 100644 --- a/lib/webpack-config-dev.js +++ b/lib/webpack-config-dev.js @@ -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"' })]; diff --git a/lib/webpack-config-prod.js b/lib/webpack-config-prod.js index 5ccb84a..ad87ea4 100644 --- a/lib/webpack-config-prod.js +++ b/lib/webpack-config-prod.js @@ -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 diff --git a/src/lib/webpack-config-dev.js b/src/lib/webpack-config-dev.js index b7f49db..91aede1 100644 --- a/src/lib/webpack-config-dev.js +++ b/src/lib/webpack-config-dev.js @@ -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 diff --git a/src/lib/webpack-config-prod.js b/src/lib/webpack-config-prod.js index 5f35b0f..8dbfea4 100644 --- a/src/lib/webpack-config-prod.js +++ b/src/lib/webpack-config-prod.js @@ -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, diff --git a/template/index.ejs b/template/index.ejs new file mode 100644 index 0000000..1ea8520 --- /dev/null +++ b/template/index.ejs @@ -0,0 +1,11 @@ + + + + + + <%= htmlWebpackPlugin.options.title %> + + +
+ + diff --git a/test/mocks/index.html b/test/mocks/index.html new file mode 100644 index 0000000..442d97f --- /dev/null +++ b/test/mocks/index.html @@ -0,0 +1,10 @@ + + + + + Document + + + + +