@gravity-ui/app-builder 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/LICENSE +21 -0
- package/README.md +9 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +46 -0
- package/dist/commands/build/build-lib.d.ts +2 -0
- package/dist/commands/build/build-lib.js +39 -0
- package/dist/commands/build/build-service/client.d.ts +2 -0
- package/dist/commands/build/build-service/client.js +8 -0
- package/dist/commands/build/build-service/index.d.ts +2 -0
- package/dist/commands/build/build-service/index.js +46 -0
- package/dist/commands/build/build-service/server.d.ts +2 -0
- package/dist/commands/build/build-service/server.js +44 -0
- package/dist/commands/build/index.d.ts +2 -0
- package/dist/commands/build/index.js +33 -0
- package/dist/commands/dev/client.d.ts +3 -0
- package/dist/commands/dev/client.js +98 -0
- package/dist/commands/dev/index.d.ts +2 -0
- package/dist/commands/dev/index.js +101 -0
- package/dist/commands/dev/server.d.ts +3 -0
- package/dist/commands/dev/server.js +38 -0
- package/dist/common/babel/index.d.ts +15 -0
- package/dist/common/babel/index.js +17 -0
- package/dist/common/babel/ui-preset.d.ts +1 -0
- package/dist/common/babel/ui-preset.js +71 -0
- package/dist/common/child-process/controllable-script.d.ts +19 -0
- package/dist/common/child-process/controllable-script.js +125 -0
- package/dist/common/child-process/utils.d.ts +1 -0
- package/dist/common/child-process/utils.js +68 -0
- package/dist/common/command.d.ts +4 -0
- package/dist/common/command.js +2 -0
- package/dist/common/config.d.ts +5 -0
- package/dist/common/config.js +155 -0
- package/dist/common/env.d.ts +1 -0
- package/dist/common/env.js +5 -0
- package/dist/common/library/index.d.ts +2 -0
- package/dist/common/library/index.js +302 -0
- package/dist/common/links/link.d.ts +1 -0
- package/dist/common/links/link.js +109 -0
- package/dist/common/links/unlink.d.ts +3 -0
- package/dist/common/links/unlink.js +72 -0
- package/dist/common/logger/colors.d.ts +12 -0
- package/dist/common/logger/colors.js +8 -0
- package/dist/common/logger/index.d.ts +47 -0
- package/dist/common/logger/index.js +120 -0
- package/dist/common/logger/pretty-time.d.ts +2 -0
- package/dist/common/logger/pretty-time.js +51 -0
- package/dist/common/models/index.d.ts +184 -0
- package/dist/common/models/index.js +11 -0
- package/dist/common/package.d.ts +19 -0
- package/dist/common/package.js +42 -0
- package/dist/common/paths.d.ts +20 -0
- package/dist/common/paths.js +28 -0
- package/dist/common/s3-upload/compress.d.ts +2 -0
- package/dist/common/s3-upload/compress.js +23 -0
- package/dist/common/s3-upload/index.d.ts +3 -0
- package/dist/common/s3-upload/index.js +7 -0
- package/dist/common/s3-upload/s3-client.d.ts +20 -0
- package/dist/common/s3-upload/s3-client.js +111 -0
- package/dist/common/s3-upload/upload.d.ts +14 -0
- package/dist/common/s3-upload/upload.js +117 -0
- package/dist/common/s3-upload/webpack-plugin.d.ts +18 -0
- package/dist/common/s3-upload/webpack-plugin.js +53 -0
- package/dist/common/tempData.d.ts +13 -0
- package/dist/common/tempData.js +43 -0
- package/dist/common/typescript/compile.d.ts +5 -0
- package/dist/common/typescript/compile.js +72 -0
- package/dist/common/typescript/diagnostic.d.ts +2 -0
- package/dist/common/typescript/diagnostic.js +46 -0
- package/dist/common/typescript/transformers.d.ts +2 -0
- package/dist/common/typescript/transformers.js +114 -0
- package/dist/common/typescript/utils.d.ts +10 -0
- package/dist/common/typescript/utils.js +53 -0
- package/dist/common/typescript/watch.d.ts +7 -0
- package/dist/common/typescript/watch.js +60 -0
- package/dist/common/utils.d.ts +2 -0
- package/dist/common/utils.js +19 -0
- package/dist/common/webpack/compile.d.ts +2 -0
- package/dist/common/webpack/compile.js +31 -0
- package/dist/common/webpack/config.d.ts +23 -0
- package/dist/common/webpack/config.js +662 -0
- package/dist/common/webpack/progress-plugin.d.ts +11 -0
- package/dist/common/webpack/progress-plugin.js +64 -0
- package/dist/common/webpack/public-path.d.ts +1 -0
- package/dist/common/webpack/public-path.js +2 -0
- package/dist/common/webpack/storybook.d.ts +13 -0
- package/dist/common/webpack/storybook.js +86 -0
- package/dist/common/webpack/utils.d.ts +7 -0
- package/dist/common/webpack/utils.js +71 -0
- package/dist/create-cli.d.ts +54 -0
- package/dist/create-cli.js +221 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +8 -0
- package/package.json +154 -0
|
@@ -0,0 +1,662 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
+
var t = {};
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
+
t[p] = s[p];
|
|
29
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
+
t[p[i]] = s[p[i]];
|
|
33
|
+
}
|
|
34
|
+
return t;
|
|
35
|
+
};
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.configureResolve = exports.configureModuleRules = exports.webpackConfigFactory = void 0;
|
|
41
|
+
/* eslint-disable complexity */
|
|
42
|
+
const path_1 = __importStar(require("path"));
|
|
43
|
+
const fs_1 = __importDefault(require("fs"));
|
|
44
|
+
const webpack = __importStar(require("webpack"));
|
|
45
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
46
|
+
const clean_webpack_plugin_1 = require("clean-webpack-plugin");
|
|
47
|
+
const webpack_manifest_plugin_1 = require("webpack-manifest-plugin");
|
|
48
|
+
const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
|
|
49
|
+
const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
|
|
50
|
+
const css_minimizer_webpack_plugin_1 = __importDefault(require("css-minimizer-webpack-plugin"));
|
|
51
|
+
const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
|
|
52
|
+
const postcss_preset_env_1 = __importDefault(require("postcss-preset-env"));
|
|
53
|
+
const webpack_assets_manifest_1 = __importDefault(require("webpack-assets-manifest"));
|
|
54
|
+
const react_refresh_webpack_plugin_1 = __importDefault(require("@pmmmwh/react-refresh-webpack-plugin"));
|
|
55
|
+
const moment_timezone_data_webpack_plugin_1 = __importDefault(require("moment-timezone-data-webpack-plugin"));
|
|
56
|
+
const webpack_plugin_1 = __importDefault(require("@statoscope/webpack-plugin"));
|
|
57
|
+
const circular_dependency_plugin_1 = __importDefault(require("circular-dependency-plugin"));
|
|
58
|
+
const paths_1 = __importDefault(require("../paths"));
|
|
59
|
+
const tempData_1 = __importDefault(require("../tempData"));
|
|
60
|
+
const babel_1 = require("../babel");
|
|
61
|
+
const progress_plugin_1 = require("./progress-plugin");
|
|
62
|
+
const utils_1 = require("./utils");
|
|
63
|
+
const s3_upload_1 = require("../s3-upload");
|
|
64
|
+
const imagesSizeLimit = 2048;
|
|
65
|
+
const fontSizeLimit = 8192;
|
|
66
|
+
function webpackConfigFactory(webpackMode, config, { logger } = {}) {
|
|
67
|
+
const isEnvDevelopment = webpackMode === "development" /* WebpackMode.Dev */;
|
|
68
|
+
const isEnvProduction = webpackMode === "production" /* WebpackMode.Prod */;
|
|
69
|
+
const { updateIncludes, tsLinkedPackages } = updateIncludesFactory();
|
|
70
|
+
const helperOptions = {
|
|
71
|
+
config,
|
|
72
|
+
logger,
|
|
73
|
+
isEnvDevelopment,
|
|
74
|
+
isEnvProduction,
|
|
75
|
+
updateIncludes,
|
|
76
|
+
tsLinkedPackages,
|
|
77
|
+
};
|
|
78
|
+
return {
|
|
79
|
+
mode: webpackMode,
|
|
80
|
+
context: paths_1.default.app,
|
|
81
|
+
bail: isEnvProduction,
|
|
82
|
+
devtool: configureDevTool(helperOptions),
|
|
83
|
+
entry: configureEntry(helperOptions),
|
|
84
|
+
output: configureOutput(helperOptions),
|
|
85
|
+
resolve: configureResolve(helperOptions),
|
|
86
|
+
module: {
|
|
87
|
+
rules: configureModuleRules(helperOptions),
|
|
88
|
+
},
|
|
89
|
+
plugins: configurePlugins(helperOptions),
|
|
90
|
+
optimization: configureOptimization(helperOptions),
|
|
91
|
+
externals: config.externals,
|
|
92
|
+
node: config.node,
|
|
93
|
+
watchOptions: config.watchOptions,
|
|
94
|
+
ignoreWarnings: [/Failed to parse source map/],
|
|
95
|
+
infrastructureLogging: config.verbose
|
|
96
|
+
? {
|
|
97
|
+
colors: true,
|
|
98
|
+
level: 'verbose',
|
|
99
|
+
}
|
|
100
|
+
: undefined,
|
|
101
|
+
experiments: isEnvDevelopment
|
|
102
|
+
? {
|
|
103
|
+
lazyCompilation: config.lazyCompilation
|
|
104
|
+
? {
|
|
105
|
+
backend: {
|
|
106
|
+
client: require.resolve('./lazy-client.js'),
|
|
107
|
+
listen: config.lazyCompilation,
|
|
108
|
+
},
|
|
109
|
+
}
|
|
110
|
+
: undefined,
|
|
111
|
+
}
|
|
112
|
+
: undefined,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
exports.webpackConfigFactory = webpackConfigFactory;
|
|
116
|
+
function configureModuleRules(helperOptions) {
|
|
117
|
+
const jsLoader = createJavaScriptLoader(helperOptions);
|
|
118
|
+
return [
|
|
119
|
+
...createSourceMapRules(!helperOptions.config.disableSourceMapGeneration),
|
|
120
|
+
{
|
|
121
|
+
oneOf: [
|
|
122
|
+
createWorkerRule(helperOptions),
|
|
123
|
+
createJavaScriptRule(helperOptions, jsLoader),
|
|
124
|
+
createStylesRule(helperOptions),
|
|
125
|
+
createIconsRule(helperOptions),
|
|
126
|
+
createIconsRule(helperOptions, jsLoader),
|
|
127
|
+
...createAssetsRules(helperOptions),
|
|
128
|
+
...createFallbackRules(helperOptions),
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
];
|
|
132
|
+
}
|
|
133
|
+
exports.configureModuleRules = configureModuleRules;
|
|
134
|
+
function updateIncludesFactory() {
|
|
135
|
+
const { linkedPackages } = tempData_1.default.getSettings();
|
|
136
|
+
const linkedPackagesArr = linkedPackages
|
|
137
|
+
? linkedPackages.keys.map((key) => linkedPackages.data[key])
|
|
138
|
+
: [];
|
|
139
|
+
if (linkedPackagesArr.length === 0) {
|
|
140
|
+
return {};
|
|
141
|
+
}
|
|
142
|
+
const tsLinkedPackages = linkedPackagesArr.filter(({ typescript }) => typescript);
|
|
143
|
+
const linkedPackagesJsIncludes = linkedPackagesArr.map((data) => `${data.package}/src`);
|
|
144
|
+
const linkedPackagesRootAssetsIncludes = linkedPackagesArr.map((data) => `${data.package}/assets`);
|
|
145
|
+
const linkedPackagesRootStylesIncludes = linkedPackagesArr.map((data) => `${data.package}/styles`);
|
|
146
|
+
return {
|
|
147
|
+
updateIncludes: (includes, options) => {
|
|
148
|
+
let result = includes.filter((pathname) => lodash_1.default.every(linkedPackagesArr, (linkedPackage) =>
|
|
149
|
+
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
150
|
+
!new RegExp(linkedPackage.name).test(pathname)));
|
|
151
|
+
result = [...result, ...linkedPackagesJsIncludes];
|
|
152
|
+
if (options === null || options === void 0 ? void 0 : options.includeRootAssets) {
|
|
153
|
+
result = [...result, ...linkedPackagesRootAssetsIncludes];
|
|
154
|
+
}
|
|
155
|
+
if (options === null || options === void 0 ? void 0 : options.includeRootStyles) {
|
|
156
|
+
result = [...result, ...linkedPackagesRootStylesIncludes];
|
|
157
|
+
}
|
|
158
|
+
return result;
|
|
159
|
+
},
|
|
160
|
+
tsLinkedPackages,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function configureDevTool({ isEnvProduction, config }) {
|
|
164
|
+
let format = 'cheap-module-source-map';
|
|
165
|
+
if (isEnvProduction) {
|
|
166
|
+
format = config.hiddenSourceMap ? 'hidden-source-map' : 'source-map';
|
|
167
|
+
}
|
|
168
|
+
return config.disableSourceMapGeneration ? false : format;
|
|
169
|
+
}
|
|
170
|
+
function configureResolve({ isEnvProduction, config, tsLinkedPackages, }) {
|
|
171
|
+
let alias = config.alias || {};
|
|
172
|
+
alias = Object.entries(alias).reduce((result, [key, value]) => {
|
|
173
|
+
result[key] = path_1.default.resolve(paths_1.default.app, value);
|
|
174
|
+
return result;
|
|
175
|
+
}, {});
|
|
176
|
+
if (isEnvProduction && config.reactProfiling) {
|
|
177
|
+
alias['react-dom$'] = 'react-dom/profiling';
|
|
178
|
+
alias['scheduler/tracing'] = 'scheduler/tracing-profiling';
|
|
179
|
+
}
|
|
180
|
+
if (tsLinkedPackages) {
|
|
181
|
+
tsLinkedPackages.forEach(({ name }) => {
|
|
182
|
+
alias[`${name}$`] = `${name}/src`;
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
const { aliases, modules = [] } = (0, utils_1.resolveTsconfigPathsToAlias)(path_1.default.resolve(paths_1.default.appClient, 'tsconfig.json')) || {};
|
|
186
|
+
return {
|
|
187
|
+
alias: Object.assign(Object.assign({}, aliases), alias),
|
|
188
|
+
modules: ['node_modules', ...modules, ...(config.modules || [])],
|
|
189
|
+
extensions: ['.mjs', '.cjs', '.js', '.jsx', '.ts', '.tsx', '.json'],
|
|
190
|
+
symlinks: config.symlinks || false,
|
|
191
|
+
fallback: config.fallback,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
exports.configureResolve = configureResolve;
|
|
195
|
+
function createEntryArray(entry) {
|
|
196
|
+
return [require.resolve('./public-path'), entry];
|
|
197
|
+
}
|
|
198
|
+
function addEntry(entry, file) {
|
|
199
|
+
const newEntry = path_1.default.resolve(paths_1.default.appEntry, file);
|
|
200
|
+
return Object.assign(Object.assign({}, entry), { [path_1.default.parse(file).name]: createEntryArray(newEntry) });
|
|
201
|
+
}
|
|
202
|
+
function configureEntry({ config }) {
|
|
203
|
+
let entries = fs_1.default.readdirSync(paths_1.default.appEntry).filter((file) => /\.[jt]sx?$/.test(file));
|
|
204
|
+
if (Array.isArray(config.entryFilter) && config.entryFilter.length) {
|
|
205
|
+
entries = entries.filter((entry) => { var _a, _b; return (_a = config.entryFilter) === null || _a === void 0 ? void 0 : _a.includes((_b = entry.split('.')[0]) !== null && _b !== void 0 ? _b : ''); });
|
|
206
|
+
}
|
|
207
|
+
if (!entries.length) {
|
|
208
|
+
throw new Error('No entries were found after applying UI_CORE_ENTRY_FILTER');
|
|
209
|
+
}
|
|
210
|
+
return entries.reduce((entry, file) => addEntry(entry, file), {});
|
|
211
|
+
}
|
|
212
|
+
function getFileNames({ isEnvProduction }) {
|
|
213
|
+
return {
|
|
214
|
+
filename: isEnvProduction ? 'js/[name].[contenthash:8].js' : 'js/[name].js',
|
|
215
|
+
chunkFilename: isEnvProduction
|
|
216
|
+
? 'js/[name].[contenthash:8].chunk.js'
|
|
217
|
+
: 'js/[name].chunk.js',
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function configureOutput(_a) {
|
|
221
|
+
var { isEnvDevelopment } = _a, rest = __rest(_a, ["isEnvDevelopment"]);
|
|
222
|
+
return Object.assign(Object.assign({}, getFileNames(Object.assign({ isEnvDevelopment }, rest))), { path: paths_1.default.appBuild, pathinfo: isEnvDevelopment });
|
|
223
|
+
}
|
|
224
|
+
function createJavaScriptLoader({ isEnvProduction, isEnvDevelopment, config, }) {
|
|
225
|
+
var _a;
|
|
226
|
+
return {
|
|
227
|
+
loader: require.resolve('babel-loader'),
|
|
228
|
+
options: {
|
|
229
|
+
babelrc: false,
|
|
230
|
+
configFile: false,
|
|
231
|
+
presets: [(0, babel_1.babelPreset)(config)],
|
|
232
|
+
plugins: [
|
|
233
|
+
isEnvDevelopment &&
|
|
234
|
+
!config.disableReactRefresh && [
|
|
235
|
+
require.resolve('react-refresh/babel'),
|
|
236
|
+
((_a = config.devServer) === null || _a === void 0 ? void 0 : _a.webSocketPath)
|
|
237
|
+
? {
|
|
238
|
+
overlay: {
|
|
239
|
+
sockPath: config.devServer.webSocketPath,
|
|
240
|
+
},
|
|
241
|
+
}
|
|
242
|
+
: undefined,
|
|
243
|
+
],
|
|
244
|
+
isEnvProduction && require.resolve('babel-plugin-lodash'),
|
|
245
|
+
].filter(Boolean),
|
|
246
|
+
sourceType: 'unambiguous',
|
|
247
|
+
cacheDirectory: true,
|
|
248
|
+
cacheCompression: isEnvProduction,
|
|
249
|
+
compact: isEnvProduction,
|
|
250
|
+
sourceMap: !config.disableSourceMapGeneration,
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
function createJavaScriptRule({ updateIncludes = lodash_1.default.identity, config, isEnvProduction }, jsLoader) {
|
|
255
|
+
const include = updateIncludes([
|
|
256
|
+
paths_1.default.appClient,
|
|
257
|
+
...(config.monaco && isEnvProduction
|
|
258
|
+
? [path_1.default.resolve(paths_1.default.appNodeModules, 'monaco-editor/esm/vs')]
|
|
259
|
+
: []),
|
|
260
|
+
...(config.includes || []),
|
|
261
|
+
]);
|
|
262
|
+
return {
|
|
263
|
+
test: [/\.[jt]sx?$/, /\.[cm]js$/],
|
|
264
|
+
include,
|
|
265
|
+
use: jsLoader,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
function createSourceMapRules(shouldUseSourceMap) {
|
|
269
|
+
if (shouldUseSourceMap) {
|
|
270
|
+
return [
|
|
271
|
+
{
|
|
272
|
+
test: [/\.jsx?$/, /\.[cm]js$/],
|
|
273
|
+
enforce: 'pre',
|
|
274
|
+
include: /node_modules/,
|
|
275
|
+
use: require.resolve('source-map-loader'),
|
|
276
|
+
},
|
|
277
|
+
];
|
|
278
|
+
}
|
|
279
|
+
return [];
|
|
280
|
+
}
|
|
281
|
+
function createWorkerRule(options) {
|
|
282
|
+
return {
|
|
283
|
+
test: /\.worker\.[jt]sx?$/,
|
|
284
|
+
exclude: /node_modules/,
|
|
285
|
+
use: [
|
|
286
|
+
{
|
|
287
|
+
loader: require.resolve('worker-loader'),
|
|
288
|
+
// currently workers located on cdn are not working properly, so we are enforcing loading workers from
|
|
289
|
+
// service instead
|
|
290
|
+
options: {
|
|
291
|
+
inline: 'no-fallback',
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
createJavaScriptLoader(options),
|
|
295
|
+
],
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
function createStylesRule({ isEnvDevelopment, isEnvProduction, config, }) {
|
|
299
|
+
const loaders = [];
|
|
300
|
+
if (isEnvProduction) {
|
|
301
|
+
loaders.push(mini_css_extract_plugin_1.default.loader);
|
|
302
|
+
}
|
|
303
|
+
if (isEnvDevelopment) {
|
|
304
|
+
loaders.push({
|
|
305
|
+
loader: require.resolve('style-loader'),
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
loaders.push({
|
|
309
|
+
loader: require.resolve('css-loader'),
|
|
310
|
+
options: {
|
|
311
|
+
esModule: false,
|
|
312
|
+
sourceMap: !config.disableSourceMapGeneration,
|
|
313
|
+
importLoaders: 2,
|
|
314
|
+
},
|
|
315
|
+
});
|
|
316
|
+
loaders.push({
|
|
317
|
+
loader: require.resolve('postcss-loader'),
|
|
318
|
+
options: {
|
|
319
|
+
sourceMap: !config.disableSourceMapGeneration,
|
|
320
|
+
postcssOptions: {
|
|
321
|
+
config: false,
|
|
322
|
+
plugins: [(0, postcss_preset_env_1.default)()],
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
loaders.push({
|
|
327
|
+
loader: require.resolve('resolve-url-loader'),
|
|
328
|
+
options: {
|
|
329
|
+
sourceMap: !config.disableSourceMapGeneration,
|
|
330
|
+
},
|
|
331
|
+
});
|
|
332
|
+
loaders.push({
|
|
333
|
+
loader: require.resolve('sass-loader'),
|
|
334
|
+
options: {
|
|
335
|
+
sourceMap: true,
|
|
336
|
+
sassOptions: {
|
|
337
|
+
includePaths: [paths_1.default.appClient],
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
});
|
|
341
|
+
return {
|
|
342
|
+
test: /\.s?css$/,
|
|
343
|
+
sideEffects: isEnvProduction ? true : undefined,
|
|
344
|
+
use: loaders,
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
function createIconsRule({ isEnvProduction, config }, jsLoader) {
|
|
348
|
+
const iconIncludes = config.icons || [];
|
|
349
|
+
return Object.assign({
|
|
350
|
+
// eslint-disable-next-line security/detect-unsafe-regex
|
|
351
|
+
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
|
|
352
|
+
// we can't use one rule with issuer: /\.[jt]sx?$/ cause of https://github.com/webpack/webpack/issues/9309
|
|
353
|
+
issuer: jsLoader ? undefined : /\.s?css$/, include: [
|
|
354
|
+
/icons\/.*\.svg$/,
|
|
355
|
+
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
356
|
+
...iconIncludes.map((dir) => new RegExp(dir)),
|
|
357
|
+
] }, (jsLoader
|
|
358
|
+
? {
|
|
359
|
+
use: [
|
|
360
|
+
jsLoader,
|
|
361
|
+
{
|
|
362
|
+
loader: require.resolve('@svgr/webpack'),
|
|
363
|
+
options: Object.assign({ babel: false, dimensions: false }, config.svgr),
|
|
364
|
+
},
|
|
365
|
+
],
|
|
366
|
+
}
|
|
367
|
+
: {
|
|
368
|
+
type: 'asset',
|
|
369
|
+
parser: {
|
|
370
|
+
dataUrlCondition: {
|
|
371
|
+
maxSize: imagesSizeLimit,
|
|
372
|
+
},
|
|
373
|
+
},
|
|
374
|
+
generator: {
|
|
375
|
+
filename: 'assets/images/[name].[contenthash:8][ext]',
|
|
376
|
+
publicPath: isEnvProduction ? '../' : undefined,
|
|
377
|
+
},
|
|
378
|
+
}));
|
|
379
|
+
}
|
|
380
|
+
function createAssetsRules({ updateIncludes = lodash_1.default.identity, isEnvProduction, config, }) {
|
|
381
|
+
const imagesRule = {
|
|
382
|
+
test: /\.(ico|bmp|gif|jpe?g|png|svg)$/,
|
|
383
|
+
include: updateIncludes([paths_1.default.appClient, ...(config.images || [])], {
|
|
384
|
+
includeRootAssets: true,
|
|
385
|
+
}),
|
|
386
|
+
type: 'asset',
|
|
387
|
+
parser: {
|
|
388
|
+
dataUrlCondition: {
|
|
389
|
+
maxSize: imagesSizeLimit,
|
|
390
|
+
},
|
|
391
|
+
},
|
|
392
|
+
generator: {
|
|
393
|
+
filename: 'assets/images/[name].[contenthash:8][ext]',
|
|
394
|
+
},
|
|
395
|
+
};
|
|
396
|
+
const fontsRule = {
|
|
397
|
+
test: /\.(ttf|eot|woff2?)$/,
|
|
398
|
+
include: [paths_1.default.appClient],
|
|
399
|
+
type: 'asset',
|
|
400
|
+
parser: {
|
|
401
|
+
dataUrlCondition: {
|
|
402
|
+
maxSize: fontSizeLimit,
|
|
403
|
+
},
|
|
404
|
+
},
|
|
405
|
+
generator: {
|
|
406
|
+
filename: 'assets/fonts/[name].[contenthash:8][ext]',
|
|
407
|
+
},
|
|
408
|
+
};
|
|
409
|
+
const rules = [imagesRule, fontsRule];
|
|
410
|
+
if (isEnvProduction) {
|
|
411
|
+
// with dynamic public path, imports from css files will look for assets in 'css/assets' directory
|
|
412
|
+
// we are enforcing loading them from 'assets'
|
|
413
|
+
rules.unshift({
|
|
414
|
+
test: /\.(ico|bmp|gif|jpe?g|png|svg)$/,
|
|
415
|
+
issuer: /\.s?css$/,
|
|
416
|
+
include: updateIncludes([paths_1.default.appClient, ...(config.images || [])], {
|
|
417
|
+
includeRootAssets: true,
|
|
418
|
+
}),
|
|
419
|
+
type: 'asset',
|
|
420
|
+
parser: {
|
|
421
|
+
dataUrlCondition: {
|
|
422
|
+
maxSize: imagesSizeLimit,
|
|
423
|
+
},
|
|
424
|
+
},
|
|
425
|
+
generator: {
|
|
426
|
+
filename: 'assets/images/[name].[contenthash:8][ext]',
|
|
427
|
+
publicPath: '../',
|
|
428
|
+
},
|
|
429
|
+
}, {
|
|
430
|
+
test: /\.(ttf|eot|woff2?)$/,
|
|
431
|
+
issuer: /\.s?css$/,
|
|
432
|
+
include: [paths_1.default.appClient],
|
|
433
|
+
type: 'asset',
|
|
434
|
+
parser: {
|
|
435
|
+
dataUrlCondition: {
|
|
436
|
+
maxSize: fontSizeLimit,
|
|
437
|
+
},
|
|
438
|
+
},
|
|
439
|
+
generator: {
|
|
440
|
+
filename: 'assets/fonts/[name].[contenthash:8][ext]',
|
|
441
|
+
publicPath: '../',
|
|
442
|
+
},
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
return rules;
|
|
446
|
+
}
|
|
447
|
+
function createFallbackRules({ isEnvProduction }) {
|
|
448
|
+
const rules = [
|
|
449
|
+
{
|
|
450
|
+
type: 'asset/resource',
|
|
451
|
+
generator: {
|
|
452
|
+
filename: 'assets/[name].[contenthash:8][ext]',
|
|
453
|
+
},
|
|
454
|
+
exclude: [/\.[jt]sx?$/, /\.json$/, /\.[cm]js$/, /\.ejs$/],
|
|
455
|
+
},
|
|
456
|
+
];
|
|
457
|
+
if (isEnvProduction) {
|
|
458
|
+
// with dynamic public path, imports from css files will look for assets in 'css/assets' directory
|
|
459
|
+
// we are enforcing loading them from 'assets'
|
|
460
|
+
rules.unshift({
|
|
461
|
+
test: /\.(ttf|eot|woff2?|bmp|gif|jpe?g|png|svg)$/,
|
|
462
|
+
issuer: /\.s?css$/,
|
|
463
|
+
type: 'asset/resource',
|
|
464
|
+
generator: {
|
|
465
|
+
filename: 'assets/[name].[contenthash:8][ext]',
|
|
466
|
+
publicPath: '../',
|
|
467
|
+
},
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
return rules;
|
|
471
|
+
}
|
|
472
|
+
function createMomentTimezoneDataPlugin(options = {}) {
|
|
473
|
+
var _a, _b;
|
|
474
|
+
const currentYear = new Date().getFullYear();
|
|
475
|
+
// By default get data for current year only
|
|
476
|
+
// https://momentjs.com/timezone/docs/#/use-it/webpack/
|
|
477
|
+
const startYear = (_a = options.startYear) !== null && _a !== void 0 ? _a : currentYear;
|
|
478
|
+
const endYear = (_b = options.endYear) !== null && _b !== void 0 ? _b : currentYear;
|
|
479
|
+
return new moment_timezone_data_webpack_plugin_1.default(Object.assign(Object.assign({}, options), { startYear, endYear }));
|
|
480
|
+
}
|
|
481
|
+
function configurePlugins(options) {
|
|
482
|
+
var _a;
|
|
483
|
+
const { isEnvDevelopment, isEnvProduction, config } = options;
|
|
484
|
+
const excludeFromClean = config.excludeFromClean || [];
|
|
485
|
+
const plugins = [
|
|
486
|
+
new clean_webpack_plugin_1.CleanWebpackPlugin({
|
|
487
|
+
cleanOnceBeforeBuildPatterns: [
|
|
488
|
+
'**/*',
|
|
489
|
+
...(isEnvDevelopment ? ['!manifest.json'] : []),
|
|
490
|
+
...excludeFromClean,
|
|
491
|
+
],
|
|
492
|
+
}),
|
|
493
|
+
new webpack_manifest_plugin_1.WebpackManifestPlugin({
|
|
494
|
+
writeToFileEmit: true,
|
|
495
|
+
publicPath: '',
|
|
496
|
+
}),
|
|
497
|
+
createMomentTimezoneDataPlugin(config.momentTz),
|
|
498
|
+
new webpack.DefinePlugin(Object.assign({ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV) }, config.definitions)),
|
|
499
|
+
];
|
|
500
|
+
if (options.logger) {
|
|
501
|
+
plugins.push(new progress_plugin_1.ProgressPlugin({ logger: options.logger }));
|
|
502
|
+
}
|
|
503
|
+
if (process.env.WEBPACK_PROFILE === 'true') {
|
|
504
|
+
plugins.push(new webpack.debug.ProfilingPlugin());
|
|
505
|
+
}
|
|
506
|
+
const contextReplacement = config.contextReplacement || {};
|
|
507
|
+
plugins.push(new webpack.ContextReplacementPlugin(/moment[\\/]locale$/,
|
|
508
|
+
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
509
|
+
new RegExp(`^\\./(${(contextReplacement.moment || ['ru']).join('|')})$`)));
|
|
510
|
+
if (contextReplacement['highlight.js']) {
|
|
511
|
+
plugins.push(new webpack.ContextReplacementPlugin(/highlight\.js[\\/]lib[\\/]languages$/,
|
|
512
|
+
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
513
|
+
new RegExp(`^\\./(${contextReplacement['highlight.js'].join('|')})$`)));
|
|
514
|
+
}
|
|
515
|
+
if (config.monaco) {
|
|
516
|
+
const MonacoEditorWebpackPlugin = require('monaco-editor-webpack-plugin');
|
|
517
|
+
plugins.push(new MonacoEditorWebpackPlugin(Object.assign(Object.assign({}, config.monaco), {
|
|
518
|
+
// currently, workers located on cdn are not working properly, so we are enforcing loading workers from
|
|
519
|
+
// service instead
|
|
520
|
+
publicPath: path_1.default.normalize(config.publicPathPrefix + '/build/') })));
|
|
521
|
+
}
|
|
522
|
+
if (isEnvDevelopment && !config.disableReactRefresh) {
|
|
523
|
+
plugins.push(new react_refresh_webpack_plugin_1.default());
|
|
524
|
+
}
|
|
525
|
+
if (config.detectCircularDependencies) {
|
|
526
|
+
let circularPluginOptions = {
|
|
527
|
+
exclude: /node_modules/,
|
|
528
|
+
allowAsyncCycles: true,
|
|
529
|
+
};
|
|
530
|
+
if (typeof config.detectCircularDependencies === 'object') {
|
|
531
|
+
circularPluginOptions = config.detectCircularDependencies;
|
|
532
|
+
}
|
|
533
|
+
plugins.push(new circular_dependency_plugin_1.default(circularPluginOptions));
|
|
534
|
+
}
|
|
535
|
+
if (!config.disableForkTsChecker) {
|
|
536
|
+
plugins.push(new fork_ts_checker_webpack_plugin_1.default({
|
|
537
|
+
typescript: {
|
|
538
|
+
typescriptPath: require.resolve((0, path_1.resolve)(paths_1.default.appNodeModules, 'typescript')),
|
|
539
|
+
configFile: (0, path_1.resolve)(paths_1.default.app, 'src/ui/tsconfig.json'),
|
|
540
|
+
diagnosticOptions: {
|
|
541
|
+
syntactic: true,
|
|
542
|
+
},
|
|
543
|
+
mode: 'write-references',
|
|
544
|
+
},
|
|
545
|
+
}));
|
|
546
|
+
}
|
|
547
|
+
if ((_a = config.polyfill) === null || _a === void 0 ? void 0 : _a.process) {
|
|
548
|
+
plugins.push(new webpack.ProvidePlugin({ process: 'process/browser.js' }));
|
|
549
|
+
}
|
|
550
|
+
if (isEnvProduction) {
|
|
551
|
+
plugins.push(new mini_css_extract_plugin_1.default({
|
|
552
|
+
filename: 'css/[name].[contenthash:8].css',
|
|
553
|
+
chunkFilename: 'css/[name].[contenthash:8].chunk.css',
|
|
554
|
+
ignoreOrder: true,
|
|
555
|
+
}));
|
|
556
|
+
plugins.push(new css_minimizer_webpack_plugin_1.default({
|
|
557
|
+
minimizerOptions: {
|
|
558
|
+
preset: [
|
|
559
|
+
'default',
|
|
560
|
+
{
|
|
561
|
+
svgo: false,
|
|
562
|
+
},
|
|
563
|
+
],
|
|
564
|
+
},
|
|
565
|
+
}));
|
|
566
|
+
if (config.analyzeBundle === 'true') {
|
|
567
|
+
plugins.push(new webpack_bundle_analyzer_1.BundleAnalyzerPlugin({
|
|
568
|
+
openAnalyzer: false,
|
|
569
|
+
analyzerMode: 'static',
|
|
570
|
+
reportFilename: 'stats.html',
|
|
571
|
+
}));
|
|
572
|
+
}
|
|
573
|
+
if (config.analyzeBundle === 'statoscope') {
|
|
574
|
+
plugins.push(new webpack_plugin_1.default({
|
|
575
|
+
saveReportTo: path_1.default.resolve(paths_1.default.appBuild, 'report.html'),
|
|
576
|
+
saveStatsTo: path_1.default.resolve(paths_1.default.appBuild, 'stats.json'),
|
|
577
|
+
open: false,
|
|
578
|
+
statsOptions: {
|
|
579
|
+
all: true,
|
|
580
|
+
},
|
|
581
|
+
}));
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
const manifestFile = 'assets-manifest.json';
|
|
585
|
+
plugins.push(new webpack_assets_manifest_1.default(isEnvProduction
|
|
586
|
+
? {
|
|
587
|
+
entrypoints: true,
|
|
588
|
+
output: manifestFile,
|
|
589
|
+
}
|
|
590
|
+
: {
|
|
591
|
+
entrypoints: true,
|
|
592
|
+
writeToDisk: true,
|
|
593
|
+
output: path_1.default.resolve(paths_1.default.appBuild, manifestFile),
|
|
594
|
+
}));
|
|
595
|
+
if (config.cdn) {
|
|
596
|
+
let credentials;
|
|
597
|
+
if (process.env.FRONTEND_S3_ACCESS_KEY_ID && process.env.FRONTEND_S3_SECRET_ACCESS_KEY) {
|
|
598
|
+
credentials = {
|
|
599
|
+
accessKeyId: process.env.FRONTEND_S3_ACCESS_KEY_ID,
|
|
600
|
+
secretAccessKey: process.env.FRONTEND_S3_SECRET_ACCESS_KEY,
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
plugins.push(new s3_upload_1.S3UploadPlugin({
|
|
604
|
+
exclude: config.hiddenSourceMap ? /\.map$/ : undefined,
|
|
605
|
+
compress: config.cdn.compress,
|
|
606
|
+
s3ClientOptions: {
|
|
607
|
+
region: config.cdn.region,
|
|
608
|
+
endpoint: config.cdn.endpoint,
|
|
609
|
+
credentials,
|
|
610
|
+
},
|
|
611
|
+
s3UploadOptions: {
|
|
612
|
+
bucket: config.cdn.bucket,
|
|
613
|
+
targetPath: config.cdn.prefix,
|
|
614
|
+
},
|
|
615
|
+
}));
|
|
616
|
+
}
|
|
617
|
+
return plugins;
|
|
618
|
+
}
|
|
619
|
+
function configureOptimization({ isEnvProduction, config, }) {
|
|
620
|
+
var _a;
|
|
621
|
+
const configVendors = (_a = config.vendors) !== null && _a !== void 0 ? _a : [];
|
|
622
|
+
const vendorsList = [
|
|
623
|
+
'react',
|
|
624
|
+
'react-dom',
|
|
625
|
+
'prop-types',
|
|
626
|
+
'redux',
|
|
627
|
+
'react-redux',
|
|
628
|
+
'@reduxjs/toolkit',
|
|
629
|
+
'lodash',
|
|
630
|
+
'lodash-es',
|
|
631
|
+
'moment',
|
|
632
|
+
'bem-cn-lite',
|
|
633
|
+
'axios',
|
|
634
|
+
...configVendors,
|
|
635
|
+
];
|
|
636
|
+
const optimization = {
|
|
637
|
+
minimize: isEnvProduction && !config.reactProfiling,
|
|
638
|
+
splitChunks: {
|
|
639
|
+
chunks: 'all',
|
|
640
|
+
cacheGroups: {
|
|
641
|
+
defaultVendors: {
|
|
642
|
+
name: 'vendors',
|
|
643
|
+
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
644
|
+
test: new RegExp(`([\\\\/])node_modules\\1(${vendorsList.join('|')})\\1`),
|
|
645
|
+
priority: Infinity,
|
|
646
|
+
},
|
|
647
|
+
},
|
|
648
|
+
},
|
|
649
|
+
runtimeChunk: 'single',
|
|
650
|
+
};
|
|
651
|
+
if (config.safari10) {
|
|
652
|
+
const TerserPlugin = require('terser-webpack-plugin');
|
|
653
|
+
optimization.minimizer = [
|
|
654
|
+
new TerserPlugin({
|
|
655
|
+
terserOptions: {
|
|
656
|
+
safari10: true,
|
|
657
|
+
},
|
|
658
|
+
}),
|
|
659
|
+
];
|
|
660
|
+
}
|
|
661
|
+
return optimization;
|
|
662
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as webpack from 'webpack';
|
|
2
|
+
import type { Logger } from '../logger';
|
|
3
|
+
export declare class ProgressPlugin extends webpack.ProgressPlugin {
|
|
4
|
+
private _logger;
|
|
5
|
+
private _state;
|
|
6
|
+
constructor({ logger }: {
|
|
7
|
+
logger: Logger;
|
|
8
|
+
});
|
|
9
|
+
handler: (percent: number, message: string, ...details: string[]) => void;
|
|
10
|
+
apply(compiler: webpack.Compiler): void;
|
|
11
|
+
}
|