@gravity-ui/app-builder 0.6.1 → 0.6.3
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 +17 -0
- package/dist/common/library/babel-plugin-remove-css-imports.d.ts +6 -0
- package/dist/common/library/babel-plugin-remove-css-imports.js +15 -0
- package/dist/common/library/babel-plugin-replace-paths.d.ts +8 -0
- package/dist/common/library/babel-plugin-replace-paths.js +44 -0
- package/dist/common/library/index.js +8 -11
- package/dist/common/webpack/config.js +47 -20
- package/dist/common/webpack/worker/worker-loader.js +18 -5
- package/package.json +6 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.6.3](https://github.com/gravity-ui/app-builder/compare/v0.6.2...v0.6.3) (2023-07-31)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* **build-lib:** replace style and svg paths with babel plugin ([#60](https://github.com/gravity-ui/app-builder/issues/60)) ([3b7760e](https://github.com/gravity-ui/app-builder/commit/3b7760e0af7350e60c9d3c7a704e510958d46050))
|
|
9
|
+
* **build:** always dedupe css modules ([#55](https://github.com/gravity-ui/app-builder/issues/55)) ([6ea483e](https://github.com/gravity-ui/app-builder/commit/6ea483eb335eb24f80f9dddc33943f0a12336281))
|
|
10
|
+
* **css:** disable sass loaders for pure css ([#56](https://github.com/gravity-ui/app-builder/issues/56)) ([1c23832](https://github.com/gravity-ui/app-builder/commit/1c2383299f1f4cbbc826acdd2b6231c15ab26956))
|
|
11
|
+
* **webworker:** correctly handle licenses and do not emit assets twice ([#58](https://github.com/gravity-ui/app-builder/issues/58)) ([e514bc6](https://github.com/gravity-ui/app-builder/commit/e514bc68ac9bed6cbbfaeddbaa95d8ea8f459acc))
|
|
12
|
+
|
|
13
|
+
## [0.6.2](https://github.com/gravity-ui/app-builder/compare/v0.6.1...v0.6.2) (2023-07-24)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* **build-lib:** correctly transform svg icons ([#53](https://github.com/gravity-ui/app-builder/issues/53)) ([9c9d3a6](https://github.com/gravity-ui/app-builder/commit/9c9d3a626ea6375a9edf93462fe0f7b367046b16))
|
|
19
|
+
|
|
3
20
|
## [0.6.1](https://github.com/gravity-ui/app-builder/compare/v0.6.0...v0.6.1) (2023-07-24)
|
|
4
21
|
|
|
5
22
|
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare const _default: (api: object, options: Record<string, any> | null | undefined, dirname: string) => {
|
|
2
|
+
visitor: {
|
|
3
|
+
ImportDeclaration(this: import("@babel/core").PluginPass, path: import("@babel/traverse").NodePath<import("@babel/types").ImportDeclaration>): void;
|
|
4
|
+
};
|
|
5
|
+
};
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const helper_plugin_utils_1 = require("@babel/helper-plugin-utils");
|
|
4
|
+
exports.default = (0, helper_plugin_utils_1.declare)(function () {
|
|
5
|
+
return {
|
|
6
|
+
visitor: {
|
|
7
|
+
ImportDeclaration(path) {
|
|
8
|
+
const source = path.node.source.value;
|
|
9
|
+
if (source.endsWith('.css')) {
|
|
10
|
+
path.remove();
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare const _default: (api: object, options: Record<string, any> | null | undefined, dirname: string) => {
|
|
2
|
+
visitor: {
|
|
3
|
+
ImportDeclaration(this: import("@babel/core").PluginPass, path: import("@babel/traverse").NodePath<import("@babel/types").ImportDeclaration>): void;
|
|
4
|
+
ExportNamedDeclaration(this: import("@babel/core").PluginPass, path: import("@babel/traverse").NodePath<import("@babel/types").ExportNamedDeclaration>): void;
|
|
5
|
+
CallExpression(this: import("@babel/core").PluginPass, path: import("@babel/traverse").NodePath<import("@babel/types").CallExpression>): void;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const helper_plugin_utils_1 = require("@babel/helper-plugin-utils");
|
|
4
|
+
const svgPathRe = /^\.\.\/(.*)\/assets\/(.*)\.svg$/;
|
|
5
|
+
exports.default = (0, helper_plugin_utils_1.declare)(function (api) {
|
|
6
|
+
return {
|
|
7
|
+
visitor: {
|
|
8
|
+
ImportDeclaration(path) {
|
|
9
|
+
const source = path.node.source.value;
|
|
10
|
+
if (source.startsWith('.') && source.endsWith('.scss')) {
|
|
11
|
+
path.node.source.value = source.slice(0, -4) + 'css';
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
const match = source.match(svgPathRe);
|
|
15
|
+
if (match) {
|
|
16
|
+
path.node.source.value = `${match[1]}/assets/${match[2]}`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
ExportNamedDeclaration(path) {
|
|
21
|
+
const sourceNode = path.node.source;
|
|
22
|
+
const specifier = path.node.specifiers[0];
|
|
23
|
+
if (api.types.isStringLiteral(sourceNode) &&
|
|
24
|
+
api.types.isExportSpecifier(specifier) &&
|
|
25
|
+
specifier.local.name === 'default') {
|
|
26
|
+
const match = sourceNode.value.match(svgPathRe);
|
|
27
|
+
if (match) {
|
|
28
|
+
sourceNode.value = `${match[1]}/assets/${match[2]}`;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
CallExpression(path) {
|
|
33
|
+
const firstArgument = path.node.arguments[0];
|
|
34
|
+
if (path.node.callee.type === 'Import' &&
|
|
35
|
+
api.types.isStringLiteral(firstArgument)) {
|
|
36
|
+
const match = firstArgument.value.match(svgPathRe);
|
|
37
|
+
if (match) {
|
|
38
|
+
firstArgument.value = `${match[1]}/assets/${match[2]}`;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
});
|
|
@@ -72,13 +72,13 @@ function compileToCjs(code, file, inputSourceMap, sourceDir = paths_1.default.sr
|
|
|
72
72
|
const compiledCjsDir = path_1.default.dirname(compiledCjsFile);
|
|
73
73
|
const sourcemapCjsFile = getFilePath(file, { dir: compiledDir, ext: 'js.map' });
|
|
74
74
|
const sourcemapCjsUrl = `// #sourceMappingURL=${path_1.default.basename(sourcemapCjsFile)}`;
|
|
75
|
-
const finalCode = code.replace(/import '(.*)\.css';/g, '');
|
|
76
75
|
fs_1.default.mkdirSync(compiledCjsDir, { recursive: true });
|
|
77
|
-
babel.transform(
|
|
76
|
+
babel.transform(code, {
|
|
78
77
|
filename: sourceFile,
|
|
79
78
|
plugins: [
|
|
80
|
-
'
|
|
81
|
-
'@babel/plugin-
|
|
79
|
+
require.resolve('./babel-plugin-remove-css-imports'),
|
|
80
|
+
require.resolve('@babel/plugin-transform-modules-commonjs'),
|
|
81
|
+
require.resolve('@babel/plugin-proposal-dynamic-import'),
|
|
82
82
|
],
|
|
83
83
|
sourceMaps: true,
|
|
84
84
|
inputSourceMap,
|
|
@@ -193,6 +193,7 @@ function buildLibrary(config) {
|
|
|
193
193
|
},
|
|
194
194
|
],
|
|
195
195
|
require.resolve('babel-plugin-lodash'),
|
|
196
|
+
require.resolve('./babel-plugin-replace-paths'),
|
|
196
197
|
],
|
|
197
198
|
sourceMaps: true,
|
|
198
199
|
}, (err, transformed) => {
|
|
@@ -202,13 +203,8 @@ function buildLibrary(config) {
|
|
|
202
203
|
throw err;
|
|
203
204
|
}
|
|
204
205
|
else if (transformed) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
?.replace(/import (\w*) from '\.\.\/(.*)\/assets\/(.*)\.svg';/g, "import $1 from '$2/assets/$3';")
|
|
208
|
-
?.replace(/export { *default as (\w*) *} from '\.\.\/(.*)\/assets\/(.*)\.svg';/g, "export { default as $1 } from '$2/assets/$3';")
|
|
209
|
-
?.replace(/import\('\.\.\/(.*)\/assets\/(.*)\.svg'\)/g, "import('$1/assets/$2')") ?? '';
|
|
210
|
-
code += (code.length ? '\n' : '') + sourcemapUrl;
|
|
211
|
-
fs_1.default.writeFile(compiledFile, code, errorHandlerFactory(`Source compilation has failed on writing ${compiledFile}`));
|
|
206
|
+
const code = transformed.code ?? '';
|
|
207
|
+
fs_1.default.writeFile(compiledFile, (code.length ? '\n' : '') + sourcemapUrl, errorHandlerFactory(`Source compilation has failed on writing ${compiledFile}`));
|
|
212
208
|
if (transformed.map) {
|
|
213
209
|
fs_1.default.writeFile(sourcemapFile, JSON.stringify(transformed.map), errorHandlerFactory(`Source compilation has failed on writing ${sourcemapFile}`));
|
|
214
210
|
}
|
|
@@ -259,6 +255,7 @@ function buildLibrary(config) {
|
|
|
259
255
|
try {
|
|
260
256
|
const component = await (0, core_1.transform)(fs_1.default.readFileSync(iconFile, 'utf-8'), {
|
|
261
257
|
jsxRuntime: config.lib.newJsxTransform ? 'automatic' : 'classic',
|
|
258
|
+
plugins: [require.resolve('@svgr/plugin-jsx')],
|
|
262
259
|
});
|
|
263
260
|
babel.transform(component, {
|
|
264
261
|
filename: iconFile,
|
|
@@ -102,6 +102,7 @@ function configureModuleRules(helperOptions) {
|
|
|
102
102
|
createWorkerRule(helperOptions),
|
|
103
103
|
createJavaScriptRule(helperOptions, jsLoader),
|
|
104
104
|
createStylesRule(helperOptions),
|
|
105
|
+
createSassStylesRule(helperOptions),
|
|
105
106
|
createIconsRule(helperOptions),
|
|
106
107
|
createIconsRule(helperOptions, jsLoader),
|
|
107
108
|
...createAssetsRules(helperOptions),
|
|
@@ -328,7 +329,46 @@ function createWorkerRule(options) {
|
|
|
328
329
|
],
|
|
329
330
|
};
|
|
330
331
|
}
|
|
332
|
+
function createSassStylesRule({ isEnvDevelopment, isEnvProduction, config, }) {
|
|
333
|
+
const loaders = getCssLoaders({
|
|
334
|
+
isEnvDevelopment,
|
|
335
|
+
isEnvProduction,
|
|
336
|
+
config,
|
|
337
|
+
});
|
|
338
|
+
loaders.push({
|
|
339
|
+
loader: require.resolve('resolve-url-loader'),
|
|
340
|
+
options: {
|
|
341
|
+
sourceMap: !config.disableSourceMapGeneration,
|
|
342
|
+
},
|
|
343
|
+
});
|
|
344
|
+
loaders.push({
|
|
345
|
+
loader: require.resolve('sass-loader'),
|
|
346
|
+
options: {
|
|
347
|
+
sourceMap: true,
|
|
348
|
+
sassOptions: {
|
|
349
|
+
includePaths: [paths_1.default.appClient],
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
});
|
|
353
|
+
return {
|
|
354
|
+
test: /\.scss$/,
|
|
355
|
+
sideEffects: isEnvProduction ? true : undefined,
|
|
356
|
+
use: loaders,
|
|
357
|
+
};
|
|
358
|
+
}
|
|
331
359
|
function createStylesRule({ isEnvDevelopment, isEnvProduction, config, }) {
|
|
360
|
+
const loaders = getCssLoaders({
|
|
361
|
+
isEnvDevelopment,
|
|
362
|
+
isEnvProduction,
|
|
363
|
+
config,
|
|
364
|
+
});
|
|
365
|
+
return {
|
|
366
|
+
test: /\.css$/,
|
|
367
|
+
sideEffects: isEnvProduction ? true : undefined,
|
|
368
|
+
use: loaders,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
function getCssLoaders({ isEnvDevelopment, isEnvProduction, config }) {
|
|
332
372
|
const loaders = [];
|
|
333
373
|
if (isEnvProduction) {
|
|
334
374
|
loaders.push(mini_css_extract_plugin_1.default.loader);
|
|
@@ -360,26 +400,7 @@ function createStylesRule({ isEnvDevelopment, isEnvProduction, config, }) {
|
|
|
360
400
|
},
|
|
361
401
|
});
|
|
362
402
|
}
|
|
363
|
-
loaders
|
|
364
|
-
loader: require.resolve('resolve-url-loader'),
|
|
365
|
-
options: {
|
|
366
|
-
sourceMap: !config.disableSourceMapGeneration,
|
|
367
|
-
},
|
|
368
|
-
});
|
|
369
|
-
loaders.push({
|
|
370
|
-
loader: require.resolve('sass-loader'),
|
|
371
|
-
options: {
|
|
372
|
-
sourceMap: true,
|
|
373
|
-
sassOptions: {
|
|
374
|
-
includePaths: [paths_1.default.appClient],
|
|
375
|
-
},
|
|
376
|
-
},
|
|
377
|
-
});
|
|
378
|
-
return {
|
|
379
|
-
test: /\.s?css$/,
|
|
380
|
-
sideEffects: isEnvProduction ? true : undefined,
|
|
381
|
-
use: loaders,
|
|
382
|
-
};
|
|
403
|
+
return loaders;
|
|
383
404
|
}
|
|
384
405
|
function createIconsRule({ isEnvProduction, config }, jsLoader) {
|
|
385
406
|
const iconIncludes = config.icons || [];
|
|
@@ -709,6 +730,12 @@ function configureOptimization({ config }) {
|
|
|
709
730
|
test: new RegExp(`([\\\\/])node_modules\\1(${vendorsList.join('|')})\\1`),
|
|
710
731
|
priority: Infinity,
|
|
711
732
|
},
|
|
733
|
+
css: {
|
|
734
|
+
test: /\.css$/,
|
|
735
|
+
enforce: true,
|
|
736
|
+
minChunks: 2,
|
|
737
|
+
reuseExistingChunk: true,
|
|
738
|
+
},
|
|
712
739
|
},
|
|
713
740
|
},
|
|
714
741
|
runtimeChunk: 'single',
|
|
@@ -78,7 +78,7 @@ const pitch = function (request) {
|
|
|
78
78
|
if (cacheContent) {
|
|
79
79
|
return cb(null, cacheContent.content, cacheContent.map);
|
|
80
80
|
}
|
|
81
|
-
|
|
81
|
+
let content = compilation.assets[filename]?.source().toString();
|
|
82
82
|
const mapFile = `${filename}.map`;
|
|
83
83
|
let map = compilation.assets[mapFile]?.source();
|
|
84
84
|
if (map) {
|
|
@@ -88,11 +88,24 @@ const pitch = function (request) {
|
|
|
88
88
|
}
|
|
89
89
|
map = JSON.stringify(sourceMap);
|
|
90
90
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
const licenseFile = `${filename}.LICENSE.txt`;
|
|
92
|
+
const license = compilation.assets[licenseFile]?.source().toString();
|
|
93
|
+
if (license && content) {
|
|
94
|
+
if (content.startsWith('/*')) {
|
|
95
|
+
content = content.replace(/^\/\*.*?\*\//, license);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const parentCompilation = workerCompiler.parentCompilation;
|
|
99
|
+
if (parentCompilation) {
|
|
100
|
+
for (const [assetName, asset] of Object.entries(compilation.assets)) {
|
|
101
|
+
if ([filename, mapFile, licenseFile].includes(assetName)) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (parentCompilation.assetsInfo.has(assetName)) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
parentCompilation.emitAsset(assetName, asset, compilation.assetsInfo.get(assetName));
|
|
94
108
|
}
|
|
95
|
-
workerCompiler.parentCompilation?.emitAsset(assetName, asset, compilation.assetsInfo.get(assetName));
|
|
96
109
|
}
|
|
97
110
|
return cache.store(cacheIdent, cacheETag, { content, map: map?.toString() }, (storeCacheError) => {
|
|
98
111
|
if (storeCacheError) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/app-builder",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "Develop and build your React client-server projects, powered by typescript and webpack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -58,6 +58,7 @@
|
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@aws-sdk/client-s3": "^3.353.0",
|
|
60
60
|
"@babel/core": "^7.21.4",
|
|
61
|
+
"@babel/helper-plugin-utils": "^7.22.5",
|
|
61
62
|
"@babel/plugin-proposal-decorators": "^7.21.0",
|
|
62
63
|
"@babel/plugin-proposal-dynamic-import": "^7.18.6",
|
|
63
64
|
"@babel/plugin-transform-modules-commonjs": "^7.21.2",
|
|
@@ -69,6 +70,7 @@
|
|
|
69
70
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
|
|
70
71
|
"@statoscope/webpack-plugin": "^5.26.2",
|
|
71
72
|
"@svgr/core": "^8.0.0",
|
|
73
|
+
"@svgr/plugin-jsx": "^8.0.1",
|
|
72
74
|
"@svgr/webpack": "^8.0.1",
|
|
73
75
|
"babel-loader": "^9.1.2",
|
|
74
76
|
"babel-plugin-inline-react-svg": "^2.0.2",
|
|
@@ -117,9 +119,9 @@
|
|
|
117
119
|
"strip-ansi": "^6.0.1",
|
|
118
120
|
"style-loader": "^3.3.3",
|
|
119
121
|
"svgo": "^3.0.2",
|
|
122
|
+
"terser-webpack-plugin": "5.3.9",
|
|
120
123
|
"ts-node": "10.9.1",
|
|
121
124
|
"tslib": "^2.6.0",
|
|
122
|
-
"terser-webpack-plugin": "5.3.9",
|
|
123
125
|
"typescript": "^5.1.6",
|
|
124
126
|
"webpack": "^5.88.1",
|
|
125
127
|
"webpack-assets-manifest": "^5.1.0",
|
|
@@ -135,6 +137,7 @@
|
|
|
135
137
|
"@gravity-ui/eslint-config": "^1.0.2",
|
|
136
138
|
"@gravity-ui/prettier-config": "^1.0.1",
|
|
137
139
|
"@gravity-ui/tsconfig": "^1.0.0",
|
|
140
|
+
"@types/babel__helper-plugin-utils": "^7.10.0",
|
|
138
141
|
"@types/circular-dependency-plugin": "^5.0.5",
|
|
139
142
|
"@types/common-tags": "^1.8.1",
|
|
140
143
|
"@types/find-cache-dir": "^3.2.1",
|
|
@@ -152,6 +155,7 @@
|
|
|
152
155
|
"@types/webpack-bundle-analyzer": "^4.6.0",
|
|
153
156
|
"@types/webpack-manifest-plugin": "^3.0.5",
|
|
154
157
|
"@types/yargs": "17.0.11",
|
|
158
|
+
"babel-plugin-tester": "^11.0.4",
|
|
155
159
|
"eslint": "^8.42.0",
|
|
156
160
|
"husky": "^8.0.3",
|
|
157
161
|
"jest": "^29.5.0",
|