1 | import { normalizePath } from './utils';
|
2 | import { reactProxyOutput } from './output-react';
|
3 | import path from 'path';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | export const reactOutputTarget = (outputTarget) => ({
|
10 | type: 'custom',
|
11 | name: 'react-library',
|
12 | validate(config) {
|
13 | return normalizeOutputTarget(config, outputTarget);
|
14 | },
|
15 | async generator(config, compilerCtx, buildCtx) {
|
16 | const timespan = buildCtx.createTimeSpan(`generate react started`, true);
|
17 | await reactProxyOutput(config, compilerCtx, outputTarget, buildCtx.components);
|
18 | timespan.finish(`generate react finished`);
|
19 | },
|
20 | });
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | export function normalizeOutputTarget(config, outputTarget) {
|
29 | var _a, _b;
|
30 | const results = Object.assign(Object.assign({}, outputTarget), { excludeComponents: outputTarget.excludeComponents || [], includePolyfills: (_a = outputTarget.includePolyfills) !== null && _a !== void 0 ? _a : true, includeDefineCustomElements: (_b = outputTarget.includeDefineCustomElements) !== null && _b !== void 0 ? _b : true });
|
31 | if (config.rootDir == null) {
|
32 | throw new Error('rootDir is not set and it should be set by stencil itself');
|
33 | }
|
34 | if (outputTarget.proxiesFile == null) {
|
35 | throw new Error('proxiesFile is required');
|
36 | }
|
37 | if (outputTarget.includeDefineCustomElements && outputTarget.includeImportCustomElements) {
|
38 | throw new Error('includeDefineCustomElements cannot be used at the same time as includeImportCustomElements since includeDefineCustomElements is used for lazy loading components. Set `includeDefineCustomElements: false` in your React output target config to resolve this.');
|
39 | }
|
40 | if (outputTarget.includeImportCustomElements && outputTarget.includePolyfills) {
|
41 | throw new Error('includePolyfills cannot be used at the same time as includeImportCustomElements. Set `includePolyfills: false` in your React output target config to resolve this.');
|
42 | }
|
43 | if (outputTarget.directivesProxyFile && !path.isAbsolute(outputTarget.directivesProxyFile)) {
|
44 | results.proxiesFile = normalizePath(path.join(config.rootDir, outputTarget.proxiesFile));
|
45 | }
|
46 | return results;
|
47 | }
|