This repository was archived by the owner on Jun 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake.js
More file actions
158 lines (135 loc) · 4.51 KB
/
Copy pathmake.js
File metadata and controls
158 lines (135 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
const path = require('path');
const mkdirp = require('mkdirp');
const pages = require('../config/pages');
const pageBemjson = require('./techs/create-page-bemjson');
const techs = require('enb-bem-techs');
const bhCommonJs = require('enb-bh/techs/bh-commonjs');
const bemjsonToHtml = require('enb-bh/techs/bemjson-to-html');
const browserjsTech = require('enb-js/techs/browser-js');
const postcssTech = require('enb-postcss/techs/enb-postcss');
const borschikTech = require('enb-borschik/techs/borschik');
/**
* Здесь описаны правила сборки итоговых HTML-страниц из блоков.
* Все страницы имеют общий CSS-файл (т.н. common-bundle).
* @see https://github.com/enb-make/enb
*/
module.exports = function (config) {
const BUILD = 'build';
const DIST = 'dist';
const ASSETS = 'assets';
const CSS_TARGET = getDistFile(ASSETS, 'style.css');
const JS_TARGET = getDistFile(ASSETS, 'script.js');
const PAGES = pages.getPagesList();
mkdirp.sync(path.join(BUILD, DIST, ASSETS));
PAGES.forEach(page => {
mkdirp.sync(path.join(BUILD, DIST, page.path));
page.BEMJSON_TARGET = page.type + '.bemjson.js';
page.HTML_TARGET = getDistFile(page.path, 'index.html');
});
config.node(BUILD, nodeConfig => {
nodeConfig.addTechs([
[ techs.levels, getLevels() ],
techs.files,
techs.deps,
techs.bemjsonToBemdecl,
pageBemjson,
bhCommonJs
]);
PAGES.forEach(page => {
nodeConfig.addTech([
pageBemjson,
{
pageType: page.type,
target: page.BEMJSON_TARGET
}
]);
nodeConfig.addTech([
bemjsonToHtml,
{
bhFile: '?.bh.js',
bemjsonFile: page.BEMJSON_TARGET,
target: page.HTML_TARGET
}
]);
nodeConfig.addTarget(page.HTML_TARGET);
});
});
/**
* Сборка статики
*/
config.mode('development', () => {
config.node(BUILD, nodeConfig => {
nodeConfig.addTech([
postcssTech,
{
target: CSS_TARGET,
sourcemap: true,
plugins: getPostcssPlugins()
}
]);
nodeConfig.addTech([
browserjsTech,
{
target: JS_TARGET,
iife: true,
sourcemap: true
}
]);
nodeConfig.addTargets([ CSS_TARGET, JS_TARGET ]);
});
});
/**
* В продакшне минифицируем CSS и JS
*/
config.mode('production', () => {
config.node(BUILD, nodeConfig => {
nodeConfig.addTech([
postcssTech,
{
target: '?.pre.css',
sourcemap: false,
plugins: getPostcssPlugins()
}
]);
// Фризинг статики из CSS (картинок и шрифтов). См .borschik
nodeConfig.addTech([
borschikTech,
{
source: '?.pre.css',
target: CSS_TARGET,
minify: true,
freeze: true
}
]);
nodeConfig.addTech([
browserjsTech,
{
target: JS_TARGET,
iife: true,
compress: true,
sourcemap: false
}
]);
nodeConfig.addTargets([ CSS_TARGET, JS_TARGET ]);
});
});
// Уровни переопределения
function getLevels() {
return {
levels: [ 'vendor.blocks', 'common.blocks', 'data.blocks' ].map(level => config.resolvePath(level))
};
}
function getDistFile() {
return path.join.apply(path, [ DIST ].concat(Array.prototype.slice.call(arguments, 0)));
}
function getPostcssPlugins() {
return [
require('postcss-simple-vars'),
require('postcss-nested'),
require('postcss-cssnext')({ browsers: [ 'last 2 versions', 'Chrome >= 34', 'iOS >= 7' ] }),
require('postcss-url')({
url: 'rebase'
})
];
}
};