Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Simplifying HTML file creation
Browse files Browse the repository at this point in the history
  • Loading branch information
eliperelman committed Feb 6, 2017
1 parent fec8fda commit a70891a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 46 deletions.
1 change: 1 addition & 0 deletions packages/neutrino-preset-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"exists-file": "3.0.0",
"file-loader": "^0.10.0",
"html-webpack-plugin": "^2.28.0",
"html-webpack-template": "^6.0.1",
"karma": "^1.4.1",
"karma-chrome-launcher": "2.0.0",
"karma-coverage": "1.1.1",
Expand Down
38 changes: 15 additions & 23 deletions packages/neutrino-preset-web/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,20 @@
const exists = require('exists-file');
const webpack = require('webpack');
const HtmlPlugin = require('html-webpack-plugin');
const htmlTemplate = require('html-webpack-template');
const merge = require('deepmerge');
const config = require('neutrino-preset-base');
const path = require('path');

const CWD = process.cwd();
const SRC = path.join(CWD, 'src');
const PRESET_TEMPLATE_EJS = path.join(__dirname, 'template.ejs');
const PRESET_TEMPLATE_INDEX = path.join(__dirname, 'index.html');
const PROJECT_TEMPLATE = path.join(SRC, 'template.ejs');
const PKG = require(path.join(CWD, 'package.json'));
const FILE_LOADER = require.resolve('file-loader');
const CSS_LOADER = require.resolve('css-loader');
const STYLE_LOADER = require.resolve('style-loader');
const URL_LOADER = require.resolve('url-loader');
const MODULES = path.join(__dirname, '../node_modules');

/**
* Find best fit template.
*
* return preset template.ejs when no template found in project folder
*/
function findTemplate() {
if (exists.sync(PRESET_TEMPLATE_EJS)) {
return PRESET_TEMPLATE_EJS;
} else if (exists.sync(PRESET_TEMPLATE_INDEX)) {
return PRESET_TEMPLATE_INDEX;
}

return PROJECT_TEMPLATE;
}

config.target('web');
config.output.publicPath('./');
config.resolve.modules.add(MODULES);
Expand Down Expand Up @@ -130,11 +114,19 @@ config

config
.plugin('html')
.use(HtmlPlugin, {
template: findTemplate(),
inject: 'body',
xhtml: true
});
.use(HtmlPlugin, merge({
inject: false,
template: htmlTemplate,
appMountId: 'root',
xhtml: true,
mobile: true,
minify: {
useShortDoctype: true,
keepClosingSlash: true,
collapseWhitespace: true,
preserveLineBreaks: true,
}
}, PKG.config && PKG.config.html ? PKG.config.html : {}));

if (process.env.NODE_ENV !== 'test') {
config
Expand Down
14 changes: 0 additions & 14 deletions packages/neutrino-preset-web/src/template.ejs

This file was deleted.

22 changes: 13 additions & 9 deletions packages/neutrino-preset-web/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ dateformat@^1.0.6:
get-stdin "^4.0.1"
meow "^3.3.0"

debug@2.2.0, debug@^2.2.0, debug@~2.2.0:
debug@2.2.0, debug@~2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.2.0.tgz#f87057e995b1a1f6ae6a4960664137bc56f039da"
dependencies:
Expand All @@ -889,7 +889,7 @@ debug@2.3.3:
dependencies:
ms "0.7.2"

debug@2.6.0:
debug@2.6.0, debug@^2.2.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.0.tgz#bc596bcabe7617f11d9fa15361eded5608b8499b"
dependencies:
Expand Down Expand Up @@ -1600,6 +1600,10 @@ html-webpack-plugin@^2.28.0:
pretty-error "^2.0.2"
toposort "^1.0.0"

html-webpack-template@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/html-webpack-template/-/html-webpack-template-6.0.1.tgz#d510e9d3174adfefb83cc81c48623ba62b803321"

htmlparser2@~3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/htmlparser2/-/htmlparser2-3.3.0.tgz#cc70d05a59f6542e43f0e685c982e14c924a9efe"
Expand Down Expand Up @@ -3203,14 +3207,14 @@ select-hose@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/select-hose/-/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca"

"semver@2 || 3 || 4 || 5", semver@~4.3.3:
version "4.3.6"
resolved "https://registry.yarnpkg.com/semver/-/semver-4.3.6.tgz#300bc6e0e86374f7ba61068b5b1ecd57fc6532da"

semver@~5.3.0:
"semver@2 || 3 || 4 || 5", semver@~5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f"

semver@~4.3.3:
version "4.3.6"
resolved "https://registry.yarnpkg.com/semver/-/semver-4.3.6.tgz#300bc6e0e86374f7ba61068b5b1ecd57fc6532da"

send@0.14.2:
version "0.14.2"
resolved "https://registry.yarnpkg.com/send/-/send-0.14.2.tgz#39b0438b3f510be5dc6f667a11f71689368cdeef"
Expand Down Expand Up @@ -3498,7 +3502,7 @@ style-loader@0.13.1:
dependencies:
loader-utils "^0.2.7"

supports-color@3.1.2:
supports-color@3.1.2, supports-color@^3.1.0, supports-color@^3.1.1:
version "3.1.2"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-3.1.2.tgz#72a262894d9d408b956ca05ff37b2ed8a6e2a2d5"
dependencies:
Expand All @@ -3512,7 +3516,7 @@ supports-color@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"

supports-color@^3.1.0, supports-color@^3.1.1, supports-color@^3.2.3:
supports-color@^3.2.3:
version "3.2.3"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-3.2.3.tgz#65ac0504b3954171d8a64946b2ae3cbb8a5f54f6"
dependencies:
Expand Down

0 comments on commit a70891a

Please sign in to comment.