Skip to content
This repository was archived by the owner on Dec 7, 2023. It is now read-only.

Commit 61a9b70

Browse files
authored
Merge pull request #21 from webtime-studio/update/dependecies-update
2 parents fd52ba1 + b61ca51 commit 61a9b70

File tree

7 files changed

+137
-82
lines changed

7 files changed

+137
-82
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<h1 align="center">Create HTML boilerplate</h1>
22
<p>
3-
<img alt="Version" src="https://img.shields.io/badge/version-1.3.1-green.svg?cacheSeconds=2592000" />
4-
<img src="https://img.shields.io/badge/node-%5E10.18-green.svg" />
3+
<img alt="Версия проекта" src="https://img.shields.io/badge/version-1.4.0-green.svg?cacheSeconds=2592000" />
4+
<img alt="Минимально необходимая версия NodeJS" src="https://img.shields.io/badge/node-%5E10.18-green.svg" />
55
</p>
66

77
<p>Привет! Спасибо за то что используете наш Create HTML boilerplate.</p>
88
<p>
99
Данная сборка вдохновлена проектом с хабра и многими часами вёрстки и
1010
разработки. Здесь специально нет ничего лишнего и только набор базовых
11-
файлов, чтобы было понятно как построить базовую структуру проекта
11+
файлов, чтобы было понятно как построить базовую структуру.
1212
</p>
1313
<ul>
1414
<li>HTML</li>
@@ -48,7 +48,7 @@ myApp
4848
│ │ └── logo.svg - лого проекта
4949
│ │
5050
│ ├── js - скрипты сайта
51-
│ │ ── index.js - точка входа для скриптов
51+
│ │ ── index.js - точка входа для скриптов
5252
│ │ └── script.js - пример импортируемого модуля
5353
│ │
5454
│ ├── root - файлы, которые будут лежать в корне проекта
@@ -71,7 +71,9 @@ myApp
7171
│ └── normalize-css/ - нормализация стилей по умолчанию (https://necolas.github.io/normalize.css/)
7272
│ └── normalize.min.css - минифицированный файл
7373
74-
├── webpack - папка для конфигураций webpack
74+
├── webpack - папка для конфигураций webpack
75+
│ ├── helpers - папка с вспомоготельными функциями
76+
│ │ └── generateHtmlPlugins.js - генерация настроек для шаблонов
7577
│ └── webpack.config.js - конфиг для webpack
7678
7779
├── .editorconfig - настройки для редактора кода

package.json

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-html-boilerplate",
3-
"version": "1.3.1",
3+
"version": "1.4.0",
44
"description": "create-html-boilerplate",
55
"scripts": {
66
"stylelint": "stylelint \"source/scss/**/*.(scss|css)\"",
@@ -11,44 +11,44 @@
1111
"start": "webpack-dev-server --config webpack/webpack.config.js --open"
1212
},
1313
"dependencies": {
14-
"concurrently": "^5.3.0",
14+
"concurrently": "^6.0.0",
1515
"picturefill": "^3.0.3"
1616
},
1717
"devDependencies": {
18-
"autoprefixer": "^10.1.0",
18+
"autoprefixer": "^10.2.5",
1919
"babel-loader": "^8.2.2",
2020
"clean-webpack-plugin": "^3.0.0",
2121
"copy-webpack-plugin": "^6.4.1",
2222
"css-loader": "^4.3.0",
23-
"eslint": "^7.16.0",
23+
"eslint": "^7.23.0",
2424
"eslint-config-airbnb-base": "^14.2.1",
25-
"eslint-config-prettier": "^7.1.0",
25+
"eslint-config-prettier": "^8.1.0",
2626
"eslint-plugin-import": "^2.22.1",
27-
"eslint-plugin-prettier": "^3.3.0",
28-
"html-webpack-plugin": "^4.5.0",
27+
"eslint-plugin-prettier": "^3.3.1",
28+
"html-webpack-plugin": "^4.5.2",
2929
"imagemin-webp-webpack-plugin": "^3.3.3",
3030
"imagemin-webpack-plugin": "^2.4.2",
31-
"mini-css-extract-plugin": "^1.3.3",
31+
"mini-css-extract-plugin": "^1.4.0",
3232
"node-sass": "^4.14.1",
3333
"optimize-css-assets-webpack-plugin": "^5.0.4",
34-
"postcss-loader": "^4.1.0",
35-
"postcss": "^8.2.1",
34+
"postcss": "^8.2.9",
35+
"postcss-loader": "^4.2.0",
3636
"preload-webpack-plugin": "^3.0.0-beta.4",
3737
"prettier": "^2.2.1",
3838
"raw-loader": "^4.0.2",
39-
"sass-loader": "^10.1.0",
40-
"stylelint": "^13.8.0",
39+
"sass-loader": "^10.1.1",
40+
"stylelint": "^13.12.0",
4141
"stylelint-config-prettier": "^8.0.2",
4242
"stylelint-config-recommended-scss": "^4.2.0",
43-
"stylelint-config-standard": "^20.0.0",
44-
"stylelint-prettier": "^1.1.2",
45-
"stylelint-scss": "^3.18.0",
46-
"svg-sprite-loader": "^5.2.1",
47-
"svgo": "^1.3.2",
48-
"svgo-loader": "^2.2.1",
43+
"stylelint-config-standard": "^21.0.0",
44+
"stylelint-prettier": "^1.2.0",
45+
"stylelint-scss": "^3.19.0",
46+
"svg-sprite-loader": "^6.0.2",
47+
"svgo": "^2.3.0",
48+
"svgo-loader": "^3.0.0",
4949
"terser-webpack-plugin": "^4.2.3",
50-
"webpack": "^4.44.2",
50+
"webpack": "^4.46.0",
5151
"webpack-cli": "^3.3.12",
52-
"webpack-dev-server": "^3.11.0"
52+
"webpack-dev-server": "^3.11.2"
5353
}
5454
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<header class="header">
22
<nav class="nav container">
33
<a href="/" class="nav__logo">
4-
<img src="/img/logo.svg" />
4+
<img src="/img/logo.svg" alt="Логотип Create HTML boilerplate"/>
55
</a>
66
</nav>
77
</header>

source/html/includes/index/hero.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<section class="container">
2-
<h1 align="center">Create HTML boilerplate</h1>
2+
<h1 align="center">
3+
Create HTML boilerplate v<%= version %>
4+
</h1>
35
<p>Привет! Спасибо за то что используете наш Create HTML boilerplate.</p>
46
<p>
57
Данная сборка вдохновлена проектом с хабра и многими часами вёрстки и

source/html/views/index.html

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
<!DOCTYPE html>
22
<html lang="ru">
3-
<head>
4-
<meta charset="UTF-8" />
5-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<meta name="format-detection" content="telephone=no" />
7-
<meta name="description" content="HTML5 webpack boilerplate" />
8-
<title>HTML5 webpack boilerplate</title>
9-
<link rel="stylesheet" href="/vendors/normalize-css/normalize.min.css" />
10-
<script>
11-
if(!window.HTMLPictureElement) {
12-
document.createElement("picture");
13-
};
14-
</script>
15-
</head>
16-
<body>
17-
<!--header.html-->
18-
<%= _.template(require('../includes/common/header.html').default)({}) %>
19-
<main>
20-
<!--index/hero.html-->
21-
<%= _.template(require('../includes/index/hero.html').default)({}) %>
22-
<!--index/structure.html-->
23-
<%= _.template(require('../includes/index/structure.html').default)({}) %>
24-
</main>
25-
<!--footer.html-->
26-
<%= _.template(require('../includes/common/footer.html').default)({}) %>
27-
</body>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<meta name="format-detection" content="telephone=no" />
7+
<meta name="description" content="HTML5 webpack boilerplate" />
8+
<title>HTML5 webpack boilerplate</title>
9+
<link rel="stylesheet" href="/vendors/normalize-css/normalize.min.css" />
10+
<script>
11+
if (!window.HTMLPictureElement) {
12+
document.createElement('picture');
13+
}
14+
</script>
15+
</head>
16+
<body>
17+
<!--header.html-->
18+
<%= _.template(require('../includes/common/header.html').default)({}) %>
19+
<main>
20+
<!--index/hero.html-->
21+
<%= _.template(require('../includes/index/hero.html').default)({
22+
version: htmlWebpackPlugin.options.custom.version,
23+
}) %>
24+
<!--index/structure.html-->
25+
<%= _.template(require('../includes/index/structure.html').default)({}) %>
26+
</main>
27+
<!--footer.html-->
28+
<%= _.template(require('../includes/common/footer.html').default)({}) %>
29+
</body>
2830
</html>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const HtmlWebpackPlugin = require('html-webpack-plugin');
4+
5+
/**
6+
* Функция принимает конфиг с путём для шаблонов страниц templatesPath
7+
* и опциями, которые можно передать в эти шаблоны.
8+
* Возвращает массив HtmlWebpackPlugin сгенерированные для
9+
* каждого html файла найденного в templatesPath.
10+
*
11+
* @param templatesPath
12+
* @param options
13+
* @returns {HtmlWebpackPlugin[]}
14+
*/
15+
const generateHtmlPlugins = ({ templatesPath, options = {} }) => {
16+
const templateFiles = fs.readdirSync(path.resolve(__dirname, templatesPath));
17+
const htmlFiles = templateFiles.filter(templateFile => {
18+
const parts = templateFile.split('.');
19+
return parts[1] === 'html';
20+
});
21+
22+
return htmlFiles.map(htmlFile => {
23+
const [name, extension] = htmlFile.split('.');
24+
25+
return new HtmlWebpackPlugin({
26+
title: options.title || 'Create HTML Boilerplate',
27+
filename: `${name}.html`,
28+
template: path.resolve(
29+
__dirname,
30+
`${templatesPath}/${name}.${extension}`,
31+
),
32+
inject: true,
33+
custom: options,
34+
});
35+
});
36+
};
37+
38+
module.exports = generateHtmlPlugins;

webpack/webpack.config.js

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
const path = require('path');
2-
const fs = require('fs');
3-
42
const webpack = require('webpack');
53
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
6-
const HtmlWebpackPlugin = require('html-webpack-plugin');
74
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
85
const CopyWebpackPlugin = require('copy-webpack-plugin');
96
const ImageminPlugin = require('imagemin-webpack-plugin').default;
@@ -12,35 +9,52 @@ const TerserPlugin = require('terser-webpack-plugin');
129
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
1310
const PreloadWebpackPlugin = require('preload-webpack-plugin');
1411
const SpriteLoaderPlugin = require('svg-sprite-loader/plugin');
12+
const generateHtmlPlugins = require('./helpers/generateHtmlPlugins');
1513

14+
/**
15+
* Получает root директорию проекта.
16+
* @type {string}
17+
*/
18+
const projectRootDir = process.cwd();
19+
/**
20+
* Текущая версия проекта из package.json
21+
* @type {string}
22+
*/
23+
const version = require('../package.json').version;
24+
/**
25+
* Кастомный title для сайта
26+
* @type {string}
27+
*/
28+
const title = 'Create HTML Boilerplate';
29+
/**
30+
* Директория с шаблонами
31+
* @type {string}
32+
*/
33+
const templatesPath = path.join(projectRootDir, 'source', 'html', 'views');
34+
/**
35+
* Базовый конфиг для сайта
36+
* templatesPath – путь для HTML шаблонов (обязательный параметр)
37+
* options – любые данные которые необходимы в шаблоне (опциональный параметр)
38+
* @type {{templatesPath: string, options: {[key]: string | number | any }}}
39+
*/
40+
const config = {
41+
templatesPath,
42+
options: {
43+
version,
44+
title,
45+
},
46+
};
47+
/**
48+
* Определяет в каком режиме работает сборка – девелопмент или продакшн.
49+
* @type {boolean}
50+
*/
1651
const isProd = process.argv.indexOf('-p') !== -1;
17-
18-
function generateHtmlPlugins(templateDir) {
19-
const templateFiles = fs.readdirSync(path.resolve(__dirname, templateDir));
20-
const htmlFiles = templateFiles.filter(templateFile => {
21-
const parts = templateFile.split('.');
22-
return parts[1] === 'html';
23-
});
24-
25-
return htmlFiles.map(htmlFile => {
26-
const parts = htmlFile.split('.');
27-
const name = parts[0];
28-
const extension = parts[1];
29-
30-
return new HtmlWebpackPlugin({
31-
filename: `${name}.html`,
32-
template: path.resolve(__dirname, `${templateDir}/${name}.${extension}`),
33-
inject: true,
34-
});
35-
});
36-
}
37-
38-
const htmlPlugins = generateHtmlPlugins('../source/html/views');
52+
const htmlPlugins = generateHtmlPlugins(config);
3953

4054
module.exports = {
4155
resolve: {
4256
alias: {
43-
source: '../source',
57+
source: path.join('..', 'source'),
4458
},
4559
},
4660
mode: isProd ? 'production' : 'development',
@@ -51,7 +65,7 @@ module.exports = {
5165
},
5266
devtool: 'inline-source-map',
5367
devServer: {
54-
contentBase: path.join(__dirname, 'source/'),
68+
contentBase: path.join(projectRootDir, 'source/'),
5569
port: 9001,
5670
hot: true,
5771
compress: true,
@@ -104,9 +118,6 @@ module.exports = {
104118
new MiniCssExtractPlugin({
105119
filename: 'css/[name].min.css',
106120
}),
107-
new HtmlWebpackPlugin({
108-
template: 'source/html/views/index.html',
109-
}),
110121
new PreloadWebpackPlugin({
111122
rel: 'preload',
112123
include: 'allChunks', // or 'initial', or 'allAssets'

0 commit comments

Comments
 (0)