@gravity-ui/app-builder 0.14.0-beta.3 → 0.14.0
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.
|
@@ -49,6 +49,10 @@ async function default_1(config) {
|
|
|
49
49
|
const startNodemon = () => {
|
|
50
50
|
if (needToStartNodemon && serverCompiled && clientCompiled) {
|
|
51
51
|
logger_1.default.message('Starting application at', serverPath);
|
|
52
|
+
const nodeArgs = ['--enable-source-maps'];
|
|
53
|
+
if (inspect || inspectBrk) {
|
|
54
|
+
nodeArgs.push(`--${inspect ? 'inspect' : 'inspect-brk'}=:::${inspect || inspectBrk}`);
|
|
55
|
+
}
|
|
52
56
|
const serverWatch = config.server.watch ?? [];
|
|
53
57
|
const delay = config.server.watchThrottle;
|
|
54
58
|
const nodemonInstance = (0, nodemon_1.default)({
|
|
@@ -58,9 +62,7 @@ async function default_1(config) {
|
|
|
58
62
|
env: {
|
|
59
63
|
...(config.server.port ? { APP_PORT: `${config.server.port}` } : undefined),
|
|
60
64
|
},
|
|
61
|
-
nodeArgs
|
|
62
|
-
? [`--${inspect ? 'inspect' : 'inspect-brk'}=:::${inspect || inspectBrk}`]
|
|
63
|
-
: undefined,
|
|
65
|
+
nodeArgs,
|
|
64
66
|
watch: [serverPath, ...serverWatch],
|
|
65
67
|
delay,
|
|
66
68
|
});
|
|
@@ -44,7 +44,6 @@ const react_refresh_webpack_plugin_1 = __importDefault(require("@pmmmwh/react-re
|
|
|
44
44
|
const moment_timezone_data_webpack_plugin_1 = __importDefault(require("moment-timezone-data-webpack-plugin"));
|
|
45
45
|
const webpack_plugin_1 = __importDefault(require("@statoscope/webpack-plugin"));
|
|
46
46
|
const circular_dependency_plugin_1 = __importDefault(require("circular-dependency-plugin"));
|
|
47
|
-
const webpack_node_externals_1 = __importDefault(require("webpack-node-externals"));
|
|
48
47
|
const paths_1 = __importDefault(require("../paths"));
|
|
49
48
|
const babel_1 = require("../babel");
|
|
50
49
|
const progress_plugin_1 = require("./progress-plugin");
|
|
@@ -52,6 +51,7 @@ const utils_1 = require("./utils");
|
|
|
52
51
|
const s3_upload_1 = require("../s3-upload");
|
|
53
52
|
const log_config_1 = require("../logger/log-config");
|
|
54
53
|
const utils_2 = require("../typescript/utils");
|
|
54
|
+
const node_externals_1 = require("./node-externals");
|
|
55
55
|
const imagesSizeLimit = 2048;
|
|
56
56
|
const fontSizeLimit = 8192;
|
|
57
57
|
async function webpackConfigFactory(webpackMode, config, { logger, isSsr = false } = {}) {
|
|
@@ -72,9 +72,9 @@ async function webpackConfigFactory(webpackMode, config, { logger, isSsr = false
|
|
|
72
72
|
externals =
|
|
73
73
|
config.ssr?.noExternal === true
|
|
74
74
|
? undefined
|
|
75
|
-
: (0,
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
: (0, node_externals_1.nodeExternals)({
|
|
76
|
+
noExternal: config.ssr?.noExternal,
|
|
77
|
+
module: config.ssr?.moduleType === 'esm',
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
80
|
let webpackConfig = {
|
|
@@ -393,6 +393,12 @@ function getCssLoaders({ isEnvDevelopment, isEnvProduction, config, isSsr }, add
|
|
|
393
393
|
loaders.unshift({
|
|
394
394
|
loader: require.resolve('css-loader'),
|
|
395
395
|
options: {
|
|
396
|
+
url: {
|
|
397
|
+
filter: (url) => {
|
|
398
|
+
// ignore data uri
|
|
399
|
+
return !url.startsWith('data:');
|
|
400
|
+
},
|
|
401
|
+
},
|
|
396
402
|
sourceMap: !config.disableSourceMapGeneration,
|
|
397
403
|
importLoaders,
|
|
398
404
|
modules: {
|
|
@@ -404,17 +410,11 @@ function getCssLoaders({ isEnvDevelopment, isEnvProduction, config, isSsr }, add
|
|
|
404
410
|
},
|
|
405
411
|
});
|
|
406
412
|
if (isEnvProduction) {
|
|
407
|
-
loaders.unshift({
|
|
408
|
-
loader: mini_css_extract_plugin_1.default.loader,
|
|
409
|
-
options: { emit: isSsr ? false : undefined },
|
|
410
|
-
});
|
|
413
|
+
loaders.unshift({ loader: mini_css_extract_plugin_1.default.loader, options: { emit: !isSsr } });
|
|
411
414
|
}
|
|
412
415
|
if (isEnvDevelopment) {
|
|
413
416
|
if (isSsr || config.ssr) {
|
|
414
|
-
loaders.unshift({
|
|
415
|
-
loader: mini_css_extract_plugin_1.default.loader,
|
|
416
|
-
options: { emit: isSsr ? false : undefined },
|
|
417
|
-
});
|
|
417
|
+
loaders.unshift({ loader: mini_css_extract_plugin_1.default.loader, options: { emit: !isSsr } });
|
|
418
418
|
}
|
|
419
419
|
else {
|
|
420
420
|
loaders.unshift({
|
|
@@ -461,7 +461,7 @@ function createIconsRule({ isEnvProduction, config, isSsr }, jsLoader) {
|
|
|
461
461
|
generator: {
|
|
462
462
|
filename: 'assets/images/[name].[contenthash:8][ext]',
|
|
463
463
|
publicPath: isEnvProduction ? '../' : undefined,
|
|
464
|
-
emit: isSsr
|
|
464
|
+
emit: !isSsr,
|
|
465
465
|
},
|
|
466
466
|
}),
|
|
467
467
|
};
|
|
@@ -478,7 +478,7 @@ function createAssetsRules({ isEnvProduction, config, isSsr }) {
|
|
|
478
478
|
},
|
|
479
479
|
generator: {
|
|
480
480
|
filename: 'assets/images/[name].[contenthash:8][ext]',
|
|
481
|
-
emit: isSsr
|
|
481
|
+
emit: !isSsr,
|
|
482
482
|
},
|
|
483
483
|
};
|
|
484
484
|
const fontsRule = {
|
|
@@ -492,7 +492,7 @@ function createAssetsRules({ isEnvProduction, config, isSsr }) {
|
|
|
492
492
|
},
|
|
493
493
|
generator: {
|
|
494
494
|
filename: 'assets/fonts/[name].[contenthash:8][ext]',
|
|
495
|
-
emit: isSsr
|
|
495
|
+
emit: !isSsr,
|
|
496
496
|
},
|
|
497
497
|
};
|
|
498
498
|
const rules = [imagesRule, fontsRule];
|
|
@@ -512,7 +512,7 @@ function createAssetsRules({ isEnvProduction, config, isSsr }) {
|
|
|
512
512
|
generator: {
|
|
513
513
|
filename: 'assets/images/[name].[contenthash:8][ext]',
|
|
514
514
|
publicPath: '../',
|
|
515
|
-
emit: isSsr
|
|
515
|
+
emit: !isSsr,
|
|
516
516
|
},
|
|
517
517
|
}, {
|
|
518
518
|
test: /\.(ttf|eot|woff2?)$/,
|
|
@@ -527,7 +527,7 @@ function createAssetsRules({ isEnvProduction, config, isSsr }) {
|
|
|
527
527
|
generator: {
|
|
528
528
|
filename: 'assets/fonts/[name].[contenthash:8][ext]',
|
|
529
529
|
publicPath: '../',
|
|
530
|
-
emit: isSsr
|
|
530
|
+
emit: !isSsr,
|
|
531
531
|
},
|
|
532
532
|
});
|
|
533
533
|
}
|
|
@@ -539,7 +539,7 @@ function createFallbackRules({ isEnvProduction, isSsr }) {
|
|
|
539
539
|
type: 'asset/resource',
|
|
540
540
|
generator: {
|
|
541
541
|
filename: 'assets/[name].[contenthash:8][ext]',
|
|
542
|
-
emit: isSsr
|
|
542
|
+
emit: !isSsr,
|
|
543
543
|
},
|
|
544
544
|
exclude: [/\.[jt]sx?$/, /\.json$/, /\.[cm]js$/, /\.ejs$/],
|
|
545
545
|
},
|
|
@@ -554,7 +554,7 @@ function createFallbackRules({ isEnvProduction, isSsr }) {
|
|
|
554
554
|
generator: {
|
|
555
555
|
filename: 'assets/[name].[contenthash:8][ext]',
|
|
556
556
|
publicPath: '../',
|
|
557
|
-
emit: isSsr
|
|
557
|
+
emit: !isSsr,
|
|
558
558
|
},
|
|
559
559
|
});
|
|
560
560
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type * as webpack from 'webpack';
|
|
2
|
+
type Pattern = RegExp | ((v: string) => boolean) | string;
|
|
3
|
+
export interface NodeExternalsOptions {
|
|
4
|
+
noExternal?: Pattern | Pattern[];
|
|
5
|
+
module?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function nodeExternals({ noExternal, module }: NodeExternalsOptions): (data: webpack.ExternalItemFunctionData) => Promise<string | undefined>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,114 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.nodeExternals = nodeExternals;
|
|
30
|
+
const fs = __importStar(require("node:fs"));
|
|
31
|
+
const path = __importStar(require("node:path"));
|
|
32
|
+
const paths_1 = __importDefault(require("../paths"));
|
|
33
|
+
const webpackInternal = /^webpack\/container\/reference\//;
|
|
34
|
+
function nodeExternals({ noExternal = [], module }) {
|
|
35
|
+
const noExternals = Array().concat(webpackInternal).concat(noExternal);
|
|
36
|
+
const nodeModules = readPackagesNames(paths_1.default.appNodeModules);
|
|
37
|
+
return async (data) => {
|
|
38
|
+
const { request } = data;
|
|
39
|
+
if (!request) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
const moduleName = getModuleName(request);
|
|
43
|
+
if (!request ||
|
|
44
|
+
!containsPattern(nodeModules, moduleName) ||
|
|
45
|
+
containsPattern(noExternals, request)) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
if (!module) {
|
|
49
|
+
return `commonjs ${data.request}`;
|
|
50
|
+
}
|
|
51
|
+
if (data.dependencyType === 'commonjs' ||
|
|
52
|
+
// lodash/something without extension can't be imported so always require it
|
|
53
|
+
(moduleName === 'lodash' && request.match(/^lodash\/[\w_]+($|\/[\w_]+$)/))) {
|
|
54
|
+
return `node-commonjs ${data.request}`;
|
|
55
|
+
}
|
|
56
|
+
return `module-import ${data.request}`;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function readPackagesNames(dirName) {
|
|
60
|
+
if (!fs.existsSync(dirName)) {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
return fs
|
|
65
|
+
.readdirSync(dirName)
|
|
66
|
+
.map((module) => {
|
|
67
|
+
if (module.startsWith('.') ||
|
|
68
|
+
!fs.statSync(path.join(dirName, module)).isDirectory()) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
if (module.startsWith('@')) {
|
|
72
|
+
try {
|
|
73
|
+
return fs.readdirSync(path.join(dirName, module)).map(function (scopedMod) {
|
|
74
|
+
return module + '/' + scopedMod;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
return [module];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return module;
|
|
82
|
+
})
|
|
83
|
+
.flat()
|
|
84
|
+
.filter((v) => v !== undefined);
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function containsPattern(patterns, value) {
|
|
91
|
+
return patterns.some((pattern) => {
|
|
92
|
+
if (pattern instanceof RegExp) {
|
|
93
|
+
return pattern.test(value);
|
|
94
|
+
}
|
|
95
|
+
else if (typeof pattern === 'function') {
|
|
96
|
+
return pattern(value);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
return pattern === value;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function getModuleName(request) {
|
|
104
|
+
const req = request;
|
|
105
|
+
const delimiter = '/';
|
|
106
|
+
// check if scoped module
|
|
107
|
+
if (req.startsWith('@')) {
|
|
108
|
+
const parts = req.split(delimiter, 2);
|
|
109
|
+
if (parts.length === 2) {
|
|
110
|
+
return parts.join(delimiter);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return req.split(delimiter, 1)[0] || '';
|
|
114
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/app-builder",
|
|
3
|
-
"version": "0.14.0
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Develop and build your React client-server projects, powered by typescript and webpack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"prettier": "prettier '**/*.{md,yaml,yml,json}'",
|
|
52
52
|
"typecheck": "tsc --noEmit",
|
|
53
53
|
"test": "jest",
|
|
54
|
+
"watch": "tsc -p tsconfig.production.json --watch",
|
|
54
55
|
"build": "npm run build:clean && npm run build:compile",
|
|
55
56
|
"build:compile": "tsc -p tsconfig.production.json",
|
|
56
57
|
"build:clean": "rimraf dist",
|
|
@@ -129,7 +130,6 @@
|
|
|
129
130
|
"webpack-bundle-analyzer": "^4.10.2",
|
|
130
131
|
"webpack-dev-server": "^5.1.0",
|
|
131
132
|
"webpack-manifest-plugin": "^5.0.0",
|
|
132
|
-
"webpack-node-externals": "^3.0.0",
|
|
133
133
|
"worker-loader": "^3.0.8",
|
|
134
134
|
"yargs": "^17.7.2"
|
|
135
135
|
},
|