@tramvai/cli 6.68.6 → 6.77.2
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/README.md +1 -1
- package/bin/const.js +5 -0
- package/bin/platform.js +12 -6
- package/bin/spawn.js +6 -0
- package/lib/api/analyze/index.d.ts.map +1 -1
- package/lib/api/analyze/index.js +1 -13
- package/lib/api/analyze/index.js.map +1 -1
- package/lib/api/index.js +1 -1
- package/lib/api/index.js.map +1 -1
- package/lib/api/start/application.experimental.d.ts.map +1 -1
- package/lib/api/start/application.experimental.js +13 -0
- package/lib/api/start/application.experimental.js.map +1 -1
- package/lib/api/start/index.d.ts +1 -0
- package/lib/api/start/index.d.ts.map +1 -1
- package/lib/api/start/index.js.map +1 -1
- package/lib/builder/webpack/analyzePlugins/rsdoctor.d.ts +2 -2
- package/lib/builder/webpack/analyzePlugins/rsdoctor.d.ts.map +1 -1
- package/lib/builder/webpack/analyzePlugins/rsdoctor.js +4 -2
- package/lib/builder/webpack/analyzePlugins/rsdoctor.js.map +1 -1
- package/lib/builder/webpack/index.d.ts.map +1 -1
- package/lib/builder/webpack/index.js +14 -12
- package/lib/builder/webpack/index.js.map +1 -1
- package/lib/builder/webpack/providers/build/client.d.ts.map +1 -1
- package/lib/builder/webpack/providers/build/client.js +3 -2
- package/lib/builder/webpack/providers/build/client.js.map +1 -1
- package/lib/builder/webpack/providers/build/server.d.ts.map +1 -1
- package/lib/builder/webpack/providers/build/server.js +3 -2
- package/lib/builder/webpack/providers/build/server.js.map +1 -1
- package/lib/builder/webpack/providers/shared.d.ts.map +1 -1
- package/lib/builder/webpack/providers/shared.js +31 -1
- package/lib/builder/webpack/providers/shared.js.map +1 -1
- package/lib/builder/webpack/providers/start/shared.d.ts.map +1 -1
- package/lib/builder/webpack/providers/start/shared.js +6 -2
- package/lib/builder/webpack/providers/start/shared.js.map +1 -1
- package/lib/builder/webpack/tokens.d.ts +2 -0
- package/lib/builder/webpack/tokens.d.ts.map +1 -1
- package/lib/cli/index.d.ts.map +1 -1
- package/lib/cli/index.js +12 -12
- package/lib/cli/index.js.map +1 -1
- package/lib/commands/analyze/command.d.ts +1 -1
- package/lib/commands/analyze/command.d.ts.map +1 -1
- package/lib/commands/build/command.d.ts.map +1 -1
- package/lib/commands/build/command.js +5 -0
- package/lib/commands/build/command.js.map +1 -1
- package/lib/commands/new/steps/installDependencies.d.ts.map +1 -1
- package/lib/commands/new/steps/installDependencies.js +3 -4
- package/lib/commands/new/steps/installDependencies.js.map +1 -1
- package/lib/commands/start/command.d.ts.map +1 -1
- package/lib/commands/start/command.js +5 -0
- package/lib/commands/start/command.js.map +1 -1
- package/lib/commands/static/application.d.ts.map +1 -1
- package/lib/commands/static/application.js +9 -3
- package/lib/commands/static/application.js.map +1 -1
- package/lib/commands/static/generate.d.ts.map +1 -1
- package/lib/commands/static/generate.js +16 -12
- package/lib/commands/static/generate.js.map +1 -1
- package/lib/config/configManager.d.ts +1 -0
- package/lib/config/configManager.d.ts.map +1 -1
- package/lib/config/configManager.js +1 -0
- package/lib/config/configManager.js.map +1 -1
- package/lib/di/tokens/config.d.ts +1 -0
- package/lib/di/tokens/config.d.ts.map +1 -1
- package/lib/library/webpack/blocks/css.d.ts.map +1 -1
- package/lib/library/webpack/blocks/css.js +23 -9
- package/lib/library/webpack/blocks/css.js.map +1 -1
- package/lib/library/webpack/blocks/js.d.ts.map +1 -1
- package/lib/library/webpack/blocks/js.js +52 -11
- package/lib/library/webpack/blocks/js.js.map +1 -1
- package/lib/library/webpack/common/main.d.ts.map +1 -1
- package/lib/library/webpack/common/main.js +2 -1
- package/lib/library/webpack/common/main.js.map +1 -1
- package/lib/schema/autogeneratedSchema.json +204 -15
- package/lib/typings/configEntry/cli.d.ts +5 -0
- package/lib/typings/configEntry/cli.d.ts.map +1 -1
- package/lib/utils/dev-app/request.d.ts +1 -0
- package/lib/utils/dev-app/request.d.ts.map +1 -1
- package/lib/utils/dev-app/request.js +10 -1
- package/lib/utils/dev-app/request.js.map +1 -1
- package/package.json +37 -37
- package/schema.json +204 -15
- package/src/api/analyze/index.ts +3 -16
- package/src/api/index.ts +1 -1
- package/src/api/start/application.experimental.ts +14 -0
- package/src/api/start/index.ts +1 -0
- package/src/builder/webpack/analyzePlugins/rsdoctor.ts +6 -3
- package/src/builder/webpack/index.ts +16 -21
- package/src/builder/webpack/providers/build/client.ts +7 -2
- package/src/builder/webpack/providers/build/server.ts +7 -2
- package/src/builder/webpack/providers/shared.ts +45 -1
- package/src/builder/webpack/providers/start/shared.ts +7 -2
- package/src/cli/index.ts +3 -2
- package/src/commands/analyze/command.ts +1 -1
- package/src/commands/build/command.ts +6 -0
- package/src/commands/new/steps/installDependencies.ts +3 -4
- package/src/commands/new/templates/app/block/shared/header/Header.spec.tsx.hbs +7 -5
- package/src/commands/new/templates/shared/package.json.hbs +1 -1
- package/src/commands/start/command.ts +6 -0
- package/src/commands/static/application.ts +11 -4
- package/src/commands/static/generate.ts +19 -12
- package/src/config/configManager.ts +2 -0
- package/src/library/webpack/blocks/css.ts +24 -8
- package/src/library/webpack/blocks/js.ts +59 -12
- package/src/library/webpack/common/main.ts +6 -2
- package/src/models/config.spec.ts +4 -0
- package/src/schema/autogeneratedSchema.json +204 -15
- package/src/schema/tramvai.spec.ts +2 -0
- package/src/typings/configEntry/cli.ts +6 -0
- package/src/utils/dev-app/request.ts +15 -0
- package/lib/api/analyze/providers/shared.d.ts +0 -3
- package/lib/api/analyze/providers/shared.d.ts.map +0 -1
- package/lib/api/analyze/providers/shared.js +0 -23
- package/lib/api/analyze/providers/shared.js.map +0 -1
- package/lib/builder/webpack/providers/analyze/shared.d.ts +0 -3
- package/lib/builder/webpack/providers/analyze/shared.d.ts.map +0 -1
- package/lib/builder/webpack/providers/analyze/shared.js +0 -137
- package/lib/builder/webpack/providers/analyze/shared.js.map +0 -1
- package/src/api/analyze/providers/shared.ts +0 -26
- package/src/builder/webpack/providers/analyze/shared.ts +0 -156
|
@@ -47,6 +47,12 @@ class BuildCommand extends CLICommand<Params> {
|
|
|
47
47
|
value: '[forPublish]',
|
|
48
48
|
description: '<package> Prepare library package.json for publication',
|
|
49
49
|
},
|
|
50
|
+
{
|
|
51
|
+
name: '--analyze',
|
|
52
|
+
value: '[analyze]',
|
|
53
|
+
description:
|
|
54
|
+
'Run build with analyze, supported plugins: <bundle|whybundled|statoscope|rsdoctor>',
|
|
55
|
+
},
|
|
50
56
|
{
|
|
51
57
|
name: '--fileCache',
|
|
52
58
|
value: '[fileCache]',
|
|
@@ -9,10 +9,9 @@ const COMMON_JEST_DEPENDENCIES = [
|
|
|
9
9
|
'@tramvai/test-unit',
|
|
10
10
|
'@tramvai/test-react',
|
|
11
11
|
'@tramvai/test-unit-jest',
|
|
12
|
-
'@types
|
|
13
|
-
'jest@^29.
|
|
14
|
-
'jest-
|
|
15
|
-
'jest-environment-jsdom@^29.0.0',
|
|
12
|
+
'@jest/types@^29.6.3',
|
|
13
|
+
'jest@^29.7.0',
|
|
14
|
+
'jest-environment-jsdom@^29.7.0',
|
|
16
15
|
'ts-node',
|
|
17
16
|
];
|
|
18
17
|
|
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
import { testComponent } from '@tramvai/test-react';
|
|
5
5
|
import { Header } from './Header';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
describe('Header', () => {
|
|
8
|
+
it('should render header', () => {
|
|
9
|
+
const { render } = testComponent(<Header />);
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
expect(render.container.innerHTML).toMatchInlineSnapshot(
|
|
12
|
+
`"<header class="Header"><h1>Tramvai <span role="img" aria-label="Salute">🥳</span></h1></header>"`
|
|
13
|
+
);
|
|
14
|
+
});
|
|
13
15
|
});
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"start": "tramvai start {{configEntry.name}}",
|
|
10
10
|
"build": "tramvai build {{configEntry.name}}",
|
|
11
11
|
"preview": "tramvai start-prod {{configEntry.name}}",
|
|
12
|
-
"analyze": "tramvai
|
|
12
|
+
"analyze": "tramvai {{configEntry.name}} --analyze=statoscope",
|
|
13
13
|
"lint": "eslint --ext .ts,.tsx --ignore-path .gitignore ."{{#if isJest}},
|
|
14
14
|
"test": "jest --passWithNoTests",
|
|
15
15
|
"test:watch": "jest --watch",
|
|
@@ -88,6 +88,12 @@ export class StartCommand extends CLICommand<Params> {
|
|
|
88
88
|
value: '[showConfig]',
|
|
89
89
|
description: 'Show config with which cli was launched',
|
|
90
90
|
},
|
|
91
|
+
{
|
|
92
|
+
name: '--analyze',
|
|
93
|
+
value: '[analyze]',
|
|
94
|
+
description:
|
|
95
|
+
'Run build with analyze, supported plugins: <bundle|whybundled|statoscope|rsdoctor>',
|
|
96
|
+
},
|
|
91
97
|
{
|
|
92
98
|
name: '--onlyBundles',
|
|
93
99
|
value: '[onlyBundles]',
|
|
@@ -16,7 +16,7 @@ import { app } from '../index';
|
|
|
16
16
|
import { startStaticServer } from './staticServer';
|
|
17
17
|
import { startServer } from './server';
|
|
18
18
|
import { handleServerOutput } from './utils/handle-server-output';
|
|
19
|
-
import {
|
|
19
|
+
import { appPrerenderRoutes } from '../../utils/dev-app/request';
|
|
20
20
|
import { PortManager } from '../../models/port-manager';
|
|
21
21
|
|
|
22
22
|
// eslint-disable-next-line max-statements
|
|
@@ -94,10 +94,10 @@ export const staticApp = async (
|
|
|
94
94
|
...safeRequire(path.resolve(process.cwd(), 'env'), true),
|
|
95
95
|
}
|
|
96
96
|
: {}),
|
|
97
|
+
CACHE_WARMUP_DISABLED: 'true',
|
|
97
98
|
...process.env,
|
|
98
99
|
NODE_ENV: 'production',
|
|
99
100
|
TRAMVAI_CLI_COMMAND: 'static',
|
|
100
|
-
CACHE_WARMUP_DISABLED: 'true',
|
|
101
101
|
PORT: `${port}`,
|
|
102
102
|
PORT_SERVER: `${port}`,
|
|
103
103
|
TRAMVAI_CLI_ASSETS_PREFIX: staticAssetsPrefix,
|
|
@@ -105,7 +105,7 @@ export const staticApp = async (
|
|
|
105
105
|
};
|
|
106
106
|
|
|
107
107
|
const server = node(path.resolve(root, 'server.js'), [], {
|
|
108
|
-
cwd:
|
|
108
|
+
cwd: process.cwd(),
|
|
109
109
|
env: envVariables,
|
|
110
110
|
});
|
|
111
111
|
|
|
@@ -124,6 +124,13 @@ export const staticApp = async (
|
|
|
124
124
|
|
|
125
125
|
handleServerOutput(context.logger, chunk);
|
|
126
126
|
});
|
|
127
|
+
server.stderr.on('data', (chunk: Buffer) => {
|
|
128
|
+
if (server.killed) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
handleServerOutput(context.logger, chunk);
|
|
133
|
+
});
|
|
127
134
|
|
|
128
135
|
const readinessProbePath = `${clientConfigManager.httpProtocol}://localhost:${
|
|
129
136
|
envVariables.UTILITY_SERVER_PORT ?? port
|
|
@@ -145,7 +152,7 @@ export const staticApp = async (
|
|
|
145
152
|
message: `message: server started, fetch application routes`,
|
|
146
153
|
});
|
|
147
154
|
|
|
148
|
-
let paths = await
|
|
155
|
+
let paths = await appPrerenderRoutes(serverConfigManager);
|
|
149
156
|
|
|
150
157
|
if (isString(rootErrorBoundaryPath)) {
|
|
151
158
|
// implicit connection with packages/modules/server/src/server/error.ts
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { resolve, join } from 'path';
|
|
2
2
|
import PQueue from 'promise-queue';
|
|
3
3
|
import { outputFile } from 'fs-extra';
|
|
4
|
+
import { getHeaders } from '@tinkoff/request-plugin-protocol-http';
|
|
4
5
|
import type { Context } from '../../models/context';
|
|
5
6
|
import type { ConfigManager } from '../../config/configManager';
|
|
6
7
|
import type { ApplicationConfigEntry } from '../../typings/configEntry/application';
|
|
@@ -8,7 +9,6 @@ import { appRequest } from '../../utils/dev-app/request';
|
|
|
8
9
|
import type { Params } from './command';
|
|
9
10
|
|
|
10
11
|
const MAX_CONCURRENT = 10;
|
|
11
|
-
const DYNAMIC_PAGE_REGEX = /\/:.+\//g;
|
|
12
12
|
|
|
13
13
|
export const generateStatic = async (
|
|
14
14
|
context: Context,
|
|
@@ -28,7 +28,9 @@ export const generateStatic = async (
|
|
|
28
28
|
|
|
29
29
|
return result;
|
|
30
30
|
},
|
|
31
|
-
{
|
|
31
|
+
{
|
|
32
|
+
'x-tramvai-prerender': 'true',
|
|
33
|
+
} as Record<string, string>
|
|
32
34
|
);
|
|
33
35
|
|
|
34
36
|
const { rootDir, output } = configManager;
|
|
@@ -37,15 +39,7 @@ export const generateStatic = async (
|
|
|
37
39
|
for (const path of paths) {
|
|
38
40
|
promises.push(
|
|
39
41
|
q.add(async () => {
|
|
40
|
-
|
|
41
|
-
if (DYNAMIC_PAGE_REGEX.test(path)) {
|
|
42
|
-
context.logger.event({
|
|
43
|
-
type: 'warning',
|
|
44
|
-
event: 'COMMAND:STATIC:DYNAMIC_PAGE_UNSUPPORTED',
|
|
45
|
-
message: `path: ${path}, message: export dynamic pages to HTML is not supported`,
|
|
46
|
-
});
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
42
|
+
let response: any;
|
|
49
43
|
|
|
50
44
|
try {
|
|
51
45
|
context.logger.event({
|
|
@@ -54,7 +48,8 @@ export const generateStatic = async (
|
|
|
54
48
|
message: `path: ${path}, message: start fetching page`,
|
|
55
49
|
});
|
|
56
50
|
|
|
57
|
-
|
|
51
|
+
response = appRequest(configManager, path, { headers });
|
|
52
|
+
const html = await response;
|
|
58
53
|
|
|
59
54
|
await outputFile(join(staticPath, path, 'index.html'), html);
|
|
60
55
|
|
|
@@ -64,6 +59,18 @@ export const generateStatic = async (
|
|
|
64
59
|
message: `path: ${path}, message: page created successfully`,
|
|
65
60
|
});
|
|
66
61
|
} catch (e) {
|
|
62
|
+
const responseHeaders = response ? getHeaders(response) : {};
|
|
63
|
+
|
|
64
|
+
if (responseHeaders['x-tramvai-prerender-skip'] === 'true') {
|
|
65
|
+
context.logger.event({
|
|
66
|
+
type: 'debug',
|
|
67
|
+
event: 'COMMAND:STATIC:PAGE_SKIP',
|
|
68
|
+
message: `path: ${path}, message: page prerender skipped`,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
67
74
|
context.logger.event({
|
|
68
75
|
type: 'error',
|
|
69
76
|
event: 'COMMAND:STATIC:ERROR',
|
|
@@ -41,6 +41,7 @@ export interface Settings<E extends Env> {
|
|
|
41
41
|
resolveSymlinks?: boolean;
|
|
42
42
|
showConfig?: boolean;
|
|
43
43
|
onlyBundles?: string[];
|
|
44
|
+
analyze?: false | 'bundle' | 'whybundled' | 'statoscope' | 'rsdoctor';
|
|
44
45
|
disableProdOptimization?: boolean;
|
|
45
46
|
fileCache?: boolean;
|
|
46
47
|
}
|
|
@@ -135,6 +136,7 @@ export const createConfigManager = <C extends ConfigEntry = ConfigEntry, E exten
|
|
|
135
136
|
benchmark: false,
|
|
136
137
|
resolveSymlinks: true,
|
|
137
138
|
disableProdOptimization: false,
|
|
139
|
+
analyze: false,
|
|
138
140
|
onlyBundles: [],
|
|
139
141
|
// according to measures fileCache in webpack doesn't affect
|
|
140
142
|
// performance much so enable it by default as it always was before
|
|
@@ -73,17 +73,33 @@ export const cssWebpackRulesFactory =
|
|
|
73
73
|
typeof postcssConfig === 'undefined'
|
|
74
74
|
) ?? {};
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
// https://github.com/webpack-contrib/postcss-loader/blob/master/src/config.d.ts
|
|
77
|
+
const postcssOptionsFn = (loaderContext: any) => {
|
|
78
|
+
const isFnConfig = typeof postcssCfg === 'function';
|
|
79
|
+
// TODO: async config fn support?
|
|
80
|
+
const defaultConfig = isFnConfig ? postcssCfg(loaderContext) : postcssCfg;
|
|
81
|
+
// eslint-disable-next-line no-nested-ternary
|
|
82
|
+
const defaultPlugins = defaultConfig.plugins ? defaultConfig.plugins : [];
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
config: false,
|
|
86
|
+
...defaultConfig,
|
|
81
87
|
// TODO: придумать как прокинуть настройки browserslist в autoprefixer - сейчас autoprefixer добавляется в самом приложении и из
|
|
82
88
|
// конфига нет возможности задавать динамический env в зависимости от сборки. Подсунуть в сам autoprefixer после его инициализации тоже
|
|
83
89
|
// тоже не получится - https://github.com/postcss/autoprefixer/blob/10.3.1/lib/autoprefixer.js#L108
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
90
|
+
plugins: Array.isArray(defaultPlugins)
|
|
91
|
+
? [
|
|
92
|
+
require('postcss-modules-tilda'),
|
|
93
|
+
require('postcss-modules-values-replace')({ importsAsModuleRequests: true }),
|
|
94
|
+
...defaultPlugins,
|
|
95
|
+
]
|
|
96
|
+
: {
|
|
97
|
+
'postcss-modules-tilda': {},
|
|
98
|
+
'postcss-modules-values-replace': { importsAsModuleRequests: true },
|
|
99
|
+
...defaultPlugins,
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
};
|
|
87
103
|
|
|
88
104
|
// otherwise postcss-loader will use cosmiconfig to resolve postcss configuration file
|
|
89
105
|
// https://github.com/webpack-contrib/postcss-loader/blob/6f470db420f6febbea729080921050e8fe353226/src/index.js#L38
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
1
2
|
import type Config from 'webpack-chain';
|
|
2
3
|
import { modernLibsFilter } from '@tinkoff/is-modern-lib';
|
|
3
4
|
import { applyThreadLoader } from '../utils/threadLoader';
|
|
@@ -5,25 +6,22 @@ import type { ConfigManager } from '../../../config/configManager';
|
|
|
5
6
|
import { getTranspilerConfig, addTranspilerLoader } from '../utils/transpiler';
|
|
6
7
|
import type { CliConfigEntry } from '../../../typings/configEntry/cli';
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const { transpileOnlyModernLibs } = configManager;
|
|
11
|
-
|
|
12
|
-
const rule = config.module
|
|
13
|
-
.rule('js')
|
|
14
|
-
.test(/\.[cm]?js[x]?$/)
|
|
15
|
-
.batch(applyThreadLoader(configManager));
|
|
9
|
+
const projectRulesName = 'project';
|
|
10
|
+
const nodeModuleRulesName = 'node_module';
|
|
16
11
|
|
|
12
|
+
const applyProjectRules = (rule, configManager) => {
|
|
17
13
|
rule
|
|
18
|
-
.oneOf(
|
|
14
|
+
.oneOf(projectRulesName)
|
|
19
15
|
.exclude.add(/node_modules/)
|
|
20
16
|
.end()
|
|
21
17
|
.use('transpiler')
|
|
22
|
-
.batch(addTranspilerLoader(configManager, getTranspilerConfig(configManager)))
|
|
18
|
+
.batch(addTranspilerLoader(configManager, getTranspilerConfig(configManager)))
|
|
19
|
+
.end();
|
|
20
|
+
};
|
|
23
21
|
|
|
22
|
+
const applyNodeModulesRules = (rule, configManager) => {
|
|
24
23
|
rule
|
|
25
|
-
.oneOf(
|
|
26
|
-
.when(transpileOnlyModernLibs, (cfg) => cfg.include.add(modernLibsFilter))
|
|
24
|
+
.oneOf(nodeModuleRulesName)
|
|
27
25
|
.merge({
|
|
28
26
|
// true value forces to use file extensions for importing mjs modules
|
|
29
27
|
// but we want to use mjs if it exists anyway
|
|
@@ -32,3 +30,52 @@ export default (configManager: ConfigManager<CliConfigEntry>) => (config: Config
|
|
|
32
30
|
.use('transpiler')
|
|
33
31
|
.batch(addTranspilerLoader(configManager, getTranspilerConfig(configManager, { hot: false })));
|
|
34
32
|
};
|
|
33
|
+
|
|
34
|
+
// eslint-disable-next-line import/no-default-export
|
|
35
|
+
export default (configManager: ConfigManager<CliConfigEntry>) => (config: Config) => {
|
|
36
|
+
const { transpileOnlyModernLibs } = configManager;
|
|
37
|
+
const { include } = configManager.experiments.transpilation;
|
|
38
|
+
const shouldTranspileOnlyModern = transpileOnlyModernLibs || include === 'only-modern';
|
|
39
|
+
|
|
40
|
+
const rule = config.module
|
|
41
|
+
.rule('js')
|
|
42
|
+
.test(/\.[cm]?js[x]?$/)
|
|
43
|
+
.batch(applyThreadLoader(configManager));
|
|
44
|
+
|
|
45
|
+
if (configManager.env === 'production') {
|
|
46
|
+
applyProjectRules(rule, configManager);
|
|
47
|
+
applyNodeModulesRules(rule, configManager);
|
|
48
|
+
|
|
49
|
+
if (shouldTranspileOnlyModern) {
|
|
50
|
+
rule.oneOf(nodeModuleRulesName).include.add(modernLibsFilter);
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
const shouldSkipTranspiling = include === 'none';
|
|
54
|
+
const shouldSelectiveTranspile = Array.isArray(include);
|
|
55
|
+
|
|
56
|
+
if (shouldSkipTranspiling) {
|
|
57
|
+
rule.exclude
|
|
58
|
+
.add(/node_modules/)
|
|
59
|
+
.end()
|
|
60
|
+
.use('transpiler')
|
|
61
|
+
.batch(addTranspilerLoader(configManager, getTranspilerConfig(configManager)));
|
|
62
|
+
} else {
|
|
63
|
+
applyProjectRules(rule, configManager);
|
|
64
|
+
applyNodeModulesRules(rule, configManager);
|
|
65
|
+
|
|
66
|
+
if (shouldSelectiveTranspile) {
|
|
67
|
+
const includeForTranspiling = (<string[]>include).map(
|
|
68
|
+
(includePath) => new RegExp(includePath)
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
includeForTranspiling.forEach((includePath) => {
|
|
72
|
+
rule.oneOf(nodeModuleRulesName).include.add(includePath);
|
|
73
|
+
});
|
|
74
|
+
} else if (shouldTranspileOnlyModern) {
|
|
75
|
+
if (shouldTranspileOnlyModern) {
|
|
76
|
+
rule.oneOf(nodeModuleRulesName).include.add(modernLibsFilter);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
@@ -4,7 +4,7 @@ import path from 'path';
|
|
|
4
4
|
import { existsSync } from 'fs-extra';
|
|
5
5
|
import findCacheDir from 'find-cache-dir';
|
|
6
6
|
import { RsdoctorWebpackMultiplePlugin } from '@rsdoctor/webpack-plugin';
|
|
7
|
-
import {
|
|
7
|
+
import { getBenchmarkRsdoctorOptions } from '@tramvai/plugin-webpack-builder';
|
|
8
8
|
import { ignoreWarnings } from '../utils/warningsFilter';
|
|
9
9
|
import resolve from '../blocks/resolve';
|
|
10
10
|
import ignoreLocales from '../blocks/ignoreLocales';
|
|
@@ -124,6 +124,10 @@ export default (configManager: ConfigManager<CliConfigEntry>) => (config: Config
|
|
|
124
124
|
'process.env.ENABLE_DEVTOOLS':
|
|
125
125
|
process.env.ENABLE_DEVTOOLS || configManager.env === 'development',
|
|
126
126
|
|
|
127
|
+
'typeof window': JSON.stringify(
|
|
128
|
+
configManager.buildType === 'server' ? 'undefined' : 'object'
|
|
129
|
+
),
|
|
130
|
+
|
|
127
131
|
'process.env.DISABLE_EXTERNAL_SCRIPTS': process.env.DISABLE_EXTERNAL_SCRIPTS || false,
|
|
128
132
|
},
|
|
129
133
|
]);
|
|
@@ -131,7 +135,7 @@ export default (configManager: ConfigManager<CliConfigEntry>) => (config: Config
|
|
|
131
135
|
if (configManager.benchmark) {
|
|
132
136
|
config
|
|
133
137
|
.plugin('rsdoctor-benchmark')
|
|
134
|
-
.use(RsdoctorWebpackMultiplePlugin, [
|
|
138
|
+
.use(RsdoctorWebpackMultiplePlugin, [getBenchmarkRsdoctorOptions(configManager.buildType)]);
|
|
135
139
|
}
|
|
136
140
|
|
|
137
141
|
// TODO: remove after dropping support for node@14
|
|
@@ -76,6 +76,7 @@ it('should populate defaults for config', () => {
|
|
|
76
76
|
"runtimeChunk": false,
|
|
77
77
|
"serverRunner": "thread",
|
|
78
78
|
"transpilation": {
|
|
79
|
+
"include": "only-modern",
|
|
79
80
|
"loader": "babel",
|
|
80
81
|
},
|
|
81
82
|
"viewTransitions": false,
|
|
@@ -152,6 +153,7 @@ it('should populate defaults for config', () => {
|
|
|
152
153
|
"minifier": "terser",
|
|
153
154
|
"reactCompiler": false,
|
|
154
155
|
"transpilation": {
|
|
156
|
+
"include": "only-modern",
|
|
155
157
|
"loader": "babel",
|
|
156
158
|
},
|
|
157
159
|
"webpack": {
|
|
@@ -325,6 +327,7 @@ it('should populate defaults for overridable options', () => {
|
|
|
325
327
|
"runtimeChunk": false,
|
|
326
328
|
"serverRunner": "thread",
|
|
327
329
|
"transpilation": {
|
|
330
|
+
"include": "only-modern",
|
|
328
331
|
"loader": {
|
|
329
332
|
"development": "swc",
|
|
330
333
|
"production": "babel",
|
|
@@ -419,6 +422,7 @@ it('should populate defaults for overridable options', () => {
|
|
|
419
422
|
"minifier": "terser",
|
|
420
423
|
"reactCompiler": false,
|
|
421
424
|
"transpilation": {
|
|
425
|
+
"include": "only-modern",
|
|
422
426
|
"loader": {
|
|
423
427
|
"development": "babel",
|
|
424
428
|
"production": "babel",
|