@teambit/react 0.0.526 → 0.0.530

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.
@@ -7,5 +7,6 @@ export declare type ReactAppOptions = {
7
7
  bundler?: Bundler;
8
8
  devServer?: DevServer;
9
9
  deploy?: (context: DeployContext) => Promise<void>;
10
+ prerenderRoutes?: string[];
10
11
  portRange?: number[];
11
12
  };
@@ -22,7 +22,7 @@ class ReactAppType {
22
22
  }
23
23
 
24
24
  createApp(options) {
25
- return new (_react().ReactApp)(options.name, options.entry, options.portRange || [3000, 4000], this.reactEnv, options.deploy);
25
+ return new (_react().ReactApp)(options.name, options.entry, options.portRange || [3000, 4000], this.reactEnv, options.deploy, options.prerenderRoutes);
26
26
  }
27
27
 
28
28
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["react.app-type.ts"],"names":["ReactAppType","constructor","name","reactEnv","createApp","options","ReactApp","entry","portRange","deploy"],"mappings":";;;;;;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,YAAN,CAA+D;AACpEC,EAAAA,WAAW,CAAUC,IAAV,EAAgCC,QAAhC,EAAoD;AAAA,SAA1CD,IAA0C,GAA1CA,IAA0C;AAAA,SAApBC,QAAoB,GAApBA,QAAoB;AAAE;;AAEjEC,EAAAA,SAAS,CAACC,OAAD,EAA2B;AAClC,WAAO,KAAIC,iBAAJ,EAAaD,OAAO,CAACH,IAArB,EAA2BG,OAAO,CAACE,KAAnC,EAA0CF,OAAO,CAACG,SAAR,IAAqB,CAAC,IAAD,EAAO,IAAP,CAA/D,EAA6E,KAAKL,QAAlF,EAA4FE,OAAO,CAACI,MAApG,CAAP;AACD;;AALmE","sourcesContent":["import { ApplicationType } from '@teambit/application';\nimport { ReactEnv } from './react.env';\nimport { ReactAppOptions } from './react-app-options';\nimport { ReactApp } from './react.application';\n\nexport class ReactAppType implements ApplicationType<ReactAppOptions> {\n constructor(readonly name: string, private reactEnv: ReactEnv) {}\n\n createApp(options: ReactAppOptions) {\n return new ReactApp(options.name, options.entry, options.portRange || [3000, 4000], this.reactEnv, options.deploy);\n }\n}\n"]}
1
+ {"version":3,"sources":["react.app-type.ts"],"names":["ReactAppType","constructor","name","reactEnv","createApp","options","ReactApp","entry","portRange","deploy","prerenderRoutes"],"mappings":";;;;;;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,YAAN,CAA+D;AACpEC,EAAAA,WAAW,CAAUC,IAAV,EAAgCC,QAAhC,EAAoD;AAAA,SAA1CD,IAA0C,GAA1CA,IAA0C;AAAA,SAApBC,QAAoB,GAApBA,QAAoB;AAAE;;AAEjEC,EAAAA,SAAS,CAACC,OAAD,EAA2B;AAClC,WAAO,KAAIC,iBAAJ,EACLD,OAAO,CAACH,IADH,EAELG,OAAO,CAACE,KAFH,EAGLF,OAAO,CAACG,SAAR,IAAqB,CAAC,IAAD,EAAO,IAAP,CAHhB,EAIL,KAAKL,QAJA,EAKLE,OAAO,CAACI,MALH,EAMLJ,OAAO,CAACK,eANH,CAAP;AAQD;;AAZmE","sourcesContent":["import { ApplicationType } from '@teambit/application';\nimport { ReactEnv } from './react.env';\nimport { ReactAppOptions } from './react-app-options';\nimport { ReactApp } from './react.application';\n\nexport class ReactAppType implements ApplicationType<ReactAppOptions> {\n constructor(readonly name: string, private reactEnv: ReactEnv) {}\n\n createApp(options: ReactAppOptions) {\n return new ReactApp(\n options.name,\n options.entry,\n options.portRange || [3000, 4000],\n this.reactEnv,\n options.deploy,\n options.prerenderRoutes\n );\n }\n}\n"]}
@@ -8,7 +8,8 @@ export declare class ReactApp implements Application {
8
8
  readonly portRange: number[];
9
9
  private reactEnv;
10
10
  readonly deploy?: ((context: DeployContext) => Promise<void>) | undefined;
11
- constructor(name: string, entry: string[], portRange: number[], reactEnv: ReactEnv, deploy?: ((context: DeployContext) => Promise<void>) | undefined);
11
+ readonly prerenderRoutes?: string[] | undefined;
12
+ constructor(name: string, entry: string[], portRange: number[], reactEnv: ReactEnv, deploy?: ((context: DeployContext) => Promise<void>) | undefined, prerenderRoutes?: string[] | undefined);
12
13
  applicationType: string;
13
14
  run(context: AppContext): Promise<number>;
14
15
  build(context: BuildContext, aspectId: string, appCapsule: Capsule): Promise<DeployContext>;
@@ -21,6 +21,16 @@ function _defineProperty2() {
21
21
  return data;
22
22
  }
23
23
 
24
+ function _prerenderSpaPlugin() {
25
+ const data = _interopRequireDefault(require("@dreysolano/prerender-spa-plugin"));
26
+
27
+ _prerenderSpaPlugin = function () {
28
+ return data;
29
+ };
30
+
31
+ return data;
32
+ }
33
+
24
34
  function _path() {
25
35
  const data = require("path");
26
36
 
@@ -42,12 +52,13 @@ function _toolboxNetwork() {
42
52
  }
43
53
 
44
54
  class ReactApp {
45
- constructor(name, entry, portRange, reactEnv, deploy) {
55
+ constructor(name, entry, portRange, reactEnv, deploy, prerenderRoutes) {
46
56
  this.name = name;
47
57
  this.entry = entry;
48
58
  this.portRange = portRange;
49
59
  this.reactEnv = reactEnv;
50
60
  this.deploy = deploy;
61
+ this.prerenderRoutes = prerenderRoutes;
51
62
  (0, _defineProperty2().default)(this, "applicationType", 'react');
52
63
  }
53
64
 
@@ -93,6 +104,16 @@ class ReactApp {
93
104
  path: (0, _path().join)(outputPath, 'public'),
94
105
  publicPath: `/`
95
106
  });
107
+ configMutator.addPlugin(new (_prerenderSpaPlugin().default)({
108
+ staticDir: (0, _path().join)(outputPath, 'public'),
109
+ routes: this.prerenderRoutes,
110
+
111
+ postProcess(renderedRoute) {
112
+ renderedRoute.outputPath = (0, _path().join)(outputPath, 'public', `${renderedRoute.originalRoute}.html`);
113
+ return renderedRoute;
114
+ }
115
+
116
+ }));
96
117
  return configMutator;
97
118
  }]);
98
119
  await bundler.run();
@@ -1 +1 @@
1
- {"version":3,"sources":["react.application.ts"],"names":["ReactApp","constructor","name","entry","portRange","reactEnv","deploy","run","context","devServerContext","getDevServerContext","devServer","getDevServer","configMutator","addTopLevel","historyApiFallback","index","disableDotRule","raw","output","publicPath","from","to","port","Port","getPort","listen","build","aspectId","appCapsule","env","publicDir","outputPath","path","distDir","getCompiler","entries","map","require","resolve","bundlerContext","Object","assign","targets","components","component","rootPath","bundler","getBundler","deployContext","applicationType","title"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAKA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGO,MAAMA,QAAN,CAAsC;AAC3CC,EAAAA,WAAW,CACAC,IADA,EAEAC,KAFA,EAGAC,SAHA,EAIDC,QAJC,EAKAC,MALA,EAMT;AAAA,SALSJ,IAKT,GALSA,IAKT;AAAA,SAJSC,KAIT,GAJSA,KAIT;AAAA,SAHSC,SAGT,GAHSA,SAGT;AAAA,SAFQC,QAER,GAFQA,QAER;AAAA,SADSC,MACT,GADSA,MACT;AAAA,6DAEgB,OAFhB;AAAE;;AAIK,QAAHC,GAAG,CAACC,OAAD,EAAuC;AAC9C,UAAMC,gBAAgB,GAAG,KAAKC,mBAAL,CAAyBF,OAAzB,CAAzB;AACA,UAAMG,SAAS,GAAG,KAAKN,QAAL,CAAcO,YAAd,CAA2BH,gBAA3B,EAA6C,CAC5DI,aAAD,IAAmB;AACjB;AACAA,MAAAA,aAAa,CAACC,WAAd,CAA0B,WAA1B,EAAuC;AACrCC,QAAAA,kBAAkB,EAAE;AAClBC,UAAAA,KAAK,EAAE,aADW;AAElBC,UAAAA,cAAc,EAAE;AAFE;AADiB,OAAvC;AAOA,UAAI,CAACJ,aAAa,CAACK,GAAd,CAAkBC,MAAvB,EAA+BN,aAAa,CAACK,GAAd,CAAkBC,MAAlB,GAA2B,EAA3B;AAC/BN,MAAAA,aAAa,CAACK,GAAd,CAAkBC,MAAlB,CAAyBC,UAAzB,GAAsC,GAAtC;AAEA,aAAOP,aAAP;AACD,KAd4D,CAA7C,CAAlB;AAgBA,UAAM,CAACQ,IAAD,EAAOC,EAAP,I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L,EAAiB,QAAjB,CAAR;AAAoCZ,QAAAA,UAAU,EAAG;AAAjD,OAApC;AACA,aAAOP,aAAP;AACD,KAJgE,CAApC,CAA/B;AAMA,UAAMkC,OAAO,CAACxC,GAAR,EAAN;AACA,UAAM0C,aAAa,GAAGR,MAAM,CAACC,MAAP,CAAclC,OAAd,EAAuB;AAC3C0C,MAAAA,eAAe,EAAE,KAAKA,eADqB;AAE3CtB,MAAAA,QAF2C;AAG3CG,MAAAA,SAAS,EAAE,kBAAKF,UAAU,CAACI,IAAhB,EAAsBF,SAAtB,EAAiC,QAAjC;AAHgC,KAAvB,CAAtB;AAKA,WAAOkB,aAAP;AACD;;AAEOvC,EAAAA,mBAAmB,CAACF,OAAD,EAAwC;AACjE,WAAOiC,MAAM,CAACC,MAAP,CAAclC,OAAd,EAAuB;AAC5BL,MAAAA,KAAK,EAAE,KAAKA,KADgB;AAE5B2C,MAAAA,QAAQ,EAAE,EAFkB;AAG5B1B,MAAAA,UAAU,EAAG,UAAS,KAAKlB,IAAK,EAHJ;AAI5BiD,MAAAA,KAAK,EAAE,KAAKjD;AAJgB,KAAvB,CAAP;AAMD;;AA1E0C","sourcesContent":["import { join, basename } from 'path';\nimport { Capsule } from '@teambit/isolator';\nimport { Application, AppContext, DeployContext } from '@teambit/application';\nimport { BuildContext } from '@teambit/builder';\nimport { Bundler, BundlerContext, DevServerContext } from '@teambit/bundler';\nimport { Port } from '@teambit/toolbox.network.get-port';\nimport { ReactEnv } from './react.env';\n\nexport class ReactApp implements Application {\n constructor(\n readonly name: string,\n readonly entry: string[],\n readonly portRange: number[],\n private reactEnv: ReactEnv,\n readonly deploy?: (context: DeployContext) => Promise<void>\n ) {}\n\n applicationType = 'react';\n\n async run(context: AppContext): Promise<number> {\n const devServerContext = this.getDevServerContext(context);\n const devServer = this.reactEnv.getDevServer(devServerContext, [\n (configMutator) => {\n // configMutator.addTopLevel('output', { publicPath: `/public/${this.name}` });\n configMutator.addTopLevel('devServer', {\n historyApiFallback: {\n index: '/index.html',\n disableDotRule: true,\n },\n });\n\n if (!configMutator.raw.output) configMutator.raw.output = {};\n configMutator.raw.output.publicPath = '/';\n\n return configMutator;\n },\n ]);\n const [from, to] = this.portRange;\n const port = await Port.getPort(from, to);\n await devServer.listen(port);\n return port;\n }\n\n async build(context: BuildContext, aspectId: string, appCapsule: Capsule): Promise<DeployContext> {\n const reactEnv: ReactEnv = context.env;\n const publicDir = join('applications', this.name, 'build');\n const outputPath = join(appCapsule.path, publicDir);\n const { distDir } = reactEnv.getCompiler();\n const entries = this.entry.map((entry) => require.resolve(`${appCapsule.path}/${distDir}/${basename(entry)}`));\n const bundlerContext: BundlerContext = Object.assign(context, {\n targets: [\n {\n components: [appCapsule?.component],\n entries,\n outputPath,\n },\n ],\n entry: [],\n rootPath: '/',\n });\n const bundler: Bundler = await reactEnv.getBundler(bundlerContext, [\n (configMutator) => {\n configMutator.addTopLevel('output', { path: join(outputPath, 'public'), publicPath: `/` });\n return configMutator;\n },\n ]);\n await bundler.run();\n const deployContext = Object.assign(context, {\n applicationType: this.applicationType,\n aspectId,\n publicDir: join(appCapsule.path, publicDir, 'public'),\n });\n return deployContext;\n }\n\n private getDevServerContext(context: AppContext): DevServerContext {\n return Object.assign(context, {\n entry: this.entry,\n rootPath: '',\n publicPath: `public/${this.name}`,\n title: this.name,\n });\n }\n}\n"]}
1
+ {"version":3,"sources":["react.application.ts"],"names":["ReactApp","constructor","name","entry","portRange","reactEnv","deploy","prerenderRoutes","run","context","devServerContext","getDevServerContext","devServer","getDevServer","configMutator","addTopLevel","historyApiFallback","index","disableDotRule","raw","output","publicPath","from","to","port","Port","getPort","listen","build","aspectId","appCapsule","env","publicDir","outputPath","path","distDir","getCompiler","entries","map","require","resolve","bundlerContext","Object","assign","targets","components","component","rootPath","bundler","getBundler","addPlugin","PrerenderSPAPlugin","staticDir","routes","postProcess","renderedRoute","originalRoute","deployContext","applicationType","title"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;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ACrBC,QAAAA,SAAS,EAAE,kBAAKnB,UAAL,EAAiB,QAAjB,CADU;AAErBoB,QAAAA,MAAM,EAAE,KAAK9C,eAFQ;;AAGrB+C,QAAAA,WAAW,CAACC,aAAD,EAAgB;AACzBA,UAAAA,aAAa,CAACtB,UAAd,GAA2B,kBAAKA,UAAL,EAAiB,QAAjB,EAA4B,GAAEsB,aAAa,CAACC,aAAc,OAA1D,CAA3B;AACA,iBAAOD,aAAP;AACD;;AANoB,OAAvB,CADF;AAUA,aAAOzC,aAAP;AACD,KAdgE,CAApC,CAA/B;AAgBA,UAAMkC,OAAO,CAACxC,GAAR,EAAN;AACA,UAAMiD,aAAa,GAAGf,MAAM,CAACC,MAAP,CAAclC,OAAd,EAAuB;AAC3CiD,MAAAA,eAAe,EAAE,KAAKA,eADqB;AAE3C7B,MAAAA,QAF2C;AAG3CG,MAAAA,SAAS,EAAE,kBAAKF,UAAU,CAACI,IAAhB,EAAsBF,SAAtB,EAAiC,QAAjC;AAHgC,KAAvB,CAAtB;AAKA,WAAOyB,aAAP;AACD;;AAEO9C,EAAAA,mBAAmB,CAACF,OAAD,EAAwC;AACjE,WAAOiC,MAAM,CAACC,MAAP,CAAclC,OAAd,EAAuB;AAC5BN,MAAAA,KAAK,EAAE,KAAKA,KADgB;AAE5B4C,MAAAA,QAAQ,EAAE,EAFkB;AAG5B1B,MAAAA,UAAU,EAAG,UAAS,KAAKnB,IAAK,EAHJ;AAI5ByD,MAAAA,KAAK,EAAE,KAAKzD;AAJgB,KAAvB,CAAP;AAMD;;AArF0C","sourcesContent":["import PrerenderSPAPlugin from '@dreysolano/prerender-spa-plugin';\nimport { join, basename } from 'path';\nimport { Capsule } from '@teambit/isolator';\nimport { Application, AppContext, DeployContext } from '@teambit/application';\nimport { BuildContext } from '@teambit/builder';\nimport { Bundler, BundlerContext, DevServerContext } from '@teambit/bundler';\nimport { Port } from '@teambit/toolbox.network.get-port';\nimport { ReactEnv } from './react.env';\n\nexport class ReactApp implements Application {\n constructor(\n readonly name: string,\n readonly entry: string[],\n readonly portRange: number[],\n private reactEnv: ReactEnv,\n readonly deploy?: (context: DeployContext) => Promise<void>,\n readonly prerenderRoutes?: string[]\n ) {}\n\n applicationType = 'react';\n\n async run(context: AppContext): Promise<number> {\n const devServerContext = this.getDevServerContext(context);\n const devServer = this.reactEnv.getDevServer(devServerContext, [\n (configMutator) => {\n // configMutator.addTopLevel('output', { publicPath: `/public/${this.name}` });\n configMutator.addTopLevel('devServer', {\n historyApiFallback: {\n index: '/index.html',\n disableDotRule: true,\n },\n });\n\n if (!configMutator.raw.output) configMutator.raw.output = {};\n configMutator.raw.output.publicPath = '/';\n\n return configMutator;\n },\n ]);\n const [from, to] = this.portRange;\n const port = await Port.getPort(from, to);\n await devServer.listen(port);\n return port;\n }\n\n async build(context: BuildContext, aspectId: string, appCapsule: Capsule): Promise<DeployContext> {\n const reactEnv: ReactEnv = context.env;\n const publicDir = join('applications', this.name, 'build');\n const outputPath = join(appCapsule.path, publicDir);\n const { distDir } = reactEnv.getCompiler();\n const entries = this.entry.map((entry) => require.resolve(`${appCapsule.path}/${distDir}/${basename(entry)}`));\n const bundlerContext: BundlerContext = Object.assign(context, {\n targets: [\n {\n components: [appCapsule?.component],\n entries,\n outputPath,\n },\n ],\n entry: [],\n rootPath: '/',\n });\n const bundler: Bundler = await reactEnv.getBundler(bundlerContext, [\n (configMutator) => {\n configMutator.addTopLevel('output', { path: join(outputPath, 'public'), publicPath: `/` });\n configMutator.addPlugin(\n new PrerenderSPAPlugin({\n staticDir: join(outputPath, 'public'),\n routes: this.prerenderRoutes,\n postProcess(renderedRoute) {\n renderedRoute.outputPath = join(outputPath, 'public', `${renderedRoute.originalRoute}.html`);\n return renderedRoute;\n },\n })\n );\n return configMutator;\n },\n ]);\n await bundler.run();\n const deployContext = Object.assign(context, {\n applicationType: this.applicationType,\n aspectId,\n publicDir: join(appCapsule.path, publicDir, 'public'),\n });\n return deployContext;\n }\n\n private getDevServerContext(context: AppContext): DevServerContext {\n return Object.assign(context, {\n entry: this.entry,\n rootPath: '',\n publicPath: `public/${this.name}`,\n title: this.name,\n });\n }\n}\n"]}
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "@teambit/react",
3
- "version": "0.0.526",
3
+ "version": "0.0.530",
4
4
  "homepage": "https://bit.dev/teambit/react/react",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.react",
8
8
  "name": "react",
9
- "version": "0.0.526"
9
+ "version": "0.0.530"
10
10
  },
11
11
  "dependencies": {
12
12
  "react-error-boundary": "^3.0.0",
13
+ "@dreysolano/prerender-spa-plugin": "1.0.3",
13
14
  "@teambit/harmony": "0.2.11",
14
15
  "fs-extra": "10.0.0",
15
16
  "lodash": "4.17.21",
@@ -78,44 +79,44 @@
78
79
  "@teambit/react.instructions.react.adding-compositions": "0.0.6",
79
80
  "@teambit/react.instructions.react.adding-tests": "0.0.6",
80
81
  "@teambit/design.ui.pages.standalone-not-found-page": "0.0.354",
81
- "@teambit/preview": "0.0.526",
82
- "@teambit/react.ui.error-fallback": "0.0.70",
83
- "@teambit/react.ui.loader-fallback": "0.0.49",
84
- "@teambit/compositions.ui.hooks.use-composition": "0.0.124",
82
+ "@teambit/preview": "0.0.530",
83
+ "@teambit/react.ui.error-fallback": "0.0.72",
84
+ "@teambit/react.ui.loader-fallback": "0.0.51",
85
+ "@teambit/compositions.ui.hooks.use-composition": "0.0.126",
85
86
  "@teambit/design.ui.input.option-button": "0.0.26",
86
87
  "@teambit/design.ui.tooltip": "0.0.352",
87
- "@teambit/application": "0.0.168",
88
- "@teambit/bundler": "0.0.526",
89
- "@teambit/builder": "0.0.526",
90
- "@teambit/isolator": "0.0.526",
91
- "@teambit/toolbox.network.get-port": "0.0.74",
92
- "@teambit/compiler": "0.0.526",
93
- "@teambit/component.modules.component-url": "0.0.79",
94
- "@teambit/component": "0.0.526",
95
- "@teambit/envs": "0.0.526",
96
- "@teambit/eslint": "0.0.526",
97
- "@teambit/formatter": "0.0.77",
98
- "@teambit/jest": "0.0.526",
99
- "@teambit/linter": "0.0.526",
100
- "@teambit/pkg": "0.0.526",
101
- "@teambit/prettier": "0.0.77",
102
- "@teambit/react.babel.bit-react-transformer": "0.0.452",
103
- "@teambit/schema": "0.0.526",
104
- "@teambit/tester": "0.0.526",
105
- "@teambit/typescript": "0.0.526",
106
- "@teambit/webpack": "0.0.526",
107
- "@teambit/workspace": "0.0.526",
88
+ "@teambit/application": "0.0.172",
89
+ "@teambit/bundler": "0.0.530",
90
+ "@teambit/builder": "0.0.530",
91
+ "@teambit/isolator": "0.0.530",
92
+ "@teambit/toolbox.network.get-port": "0.0.76",
93
+ "@teambit/compiler": "0.0.530",
94
+ "@teambit/component.modules.component-url": "0.0.81",
95
+ "@teambit/component": "0.0.530",
96
+ "@teambit/envs": "0.0.530",
97
+ "@teambit/eslint": "0.0.530",
98
+ "@teambit/formatter": "0.0.81",
99
+ "@teambit/jest": "0.0.530",
100
+ "@teambit/linter": "0.0.530",
101
+ "@teambit/pkg": "0.0.530",
102
+ "@teambit/prettier": "0.0.81",
103
+ "@teambit/react.babel.bit-react-transformer": "0.0.454",
104
+ "@teambit/schema": "0.0.530",
105
+ "@teambit/tester": "0.0.530",
106
+ "@teambit/typescript": "0.0.530",
107
+ "@teambit/webpack": "0.0.530",
108
+ "@teambit/workspace": "0.0.530",
108
109
  "@teambit/cli": "0.0.380",
109
- "@teambit/dependency-resolver": "0.0.526",
110
- "@teambit/generator": "0.0.526",
111
- "@teambit/graphql": "0.0.526",
112
- "@teambit/react.ui.highlighter-provider": "0.0.132",
113
- "@teambit/compositions": "0.0.526",
114
- "@teambit/ui": "0.0.526",
115
- "@teambit/react.eslint-config-bit-react": "0.0.447",
116
- "@teambit/mdx.modules.mdx-loader": "0.0.448",
117
- "@teambit/webpack.modules.generate-style-loaders": "0.0.64",
118
- "@teambit/webpack.modules.style-regexps": "0.0.93",
110
+ "@teambit/dependency-resolver": "0.0.530",
111
+ "@teambit/generator": "0.0.530",
112
+ "@teambit/graphql": "0.0.530",
113
+ "@teambit/react.ui.highlighter-provider": "0.0.134",
114
+ "@teambit/compositions": "0.0.530",
115
+ "@teambit/ui": "0.0.530",
116
+ "@teambit/react.eslint-config-bit-react": "0.0.449",
117
+ "@teambit/mdx.modules.mdx-loader": "0.0.450",
118
+ "@teambit/webpack.modules.generate-style-loaders": "0.0.66",
119
+ "@teambit/webpack.modules.style-regexps": "0.0.95",
119
120
  "@teambit/component-id": "0.0.370",
120
121
  "@teambit/config": "0.0.391"
121
122
  },
@@ -132,10 +133,10 @@
132
133
  "@types/mocha": "5.2.7",
133
134
  "@types/testing-library__jest-dom": "5.9.5",
134
135
  "@types/jest": "^26.0.0",
135
- "@teambit/react.aspect-docs.react": "0.0.88"
136
+ "@teambit/react.aspect-docs.react": "0.0.90"
136
137
  },
137
138
  "peerDependencies": {
138
- "@teambit/legacy": "1.0.161",
139
+ "@teambit/legacy": "1.0.163",
139
140
  "react-dom": "^16.8.0 || ^17.0.0",
140
141
  "react": "^16.8.0 || ^17.0.0"
141
142
  },
@@ -197,7 +198,7 @@
197
198
  "@types/jest": "^26.0.0"
198
199
  },
199
200
  "peerDependencies": {
200
- "@teambit/legacy": "1.0.161",
201
+ "@teambit/legacy": "1.0.163",
201
202
  "react-dom": "^16.8.0 || ^17.0.0",
202
203
  "react": "^16.8.0 || ^17.0.0"
203
204
  }
@@ -32,6 +32,12 @@ export type ReactAppOptions = {
32
32
  */
33
33
  deploy?: (context: DeployContext) => Promise<void>;
34
34
 
35
+ /**
36
+ * prerender routes of application (will create static file for the route)
37
+ * e.g ['/plugins', '/learn', '/docs/quick-start]
38
+ */
39
+ prerenderRoutes?: string[];
40
+
35
41
  /**
36
42
  * ranges of ports to use to run the app server.
37
43
  */
package/react.app-type.ts CHANGED
@@ -7,6 +7,13 @@ export class ReactAppType implements ApplicationType<ReactAppOptions> {
7
7
  constructor(readonly name: string, private reactEnv: ReactEnv) {}
8
8
 
9
9
  createApp(options: ReactAppOptions) {
10
- return new ReactApp(options.name, options.entry, options.portRange || [3000, 4000], this.reactEnv, options.deploy);
10
+ return new ReactApp(
11
+ options.name,
12
+ options.entry,
13
+ options.portRange || [3000, 4000],
14
+ this.reactEnv,
15
+ options.deploy,
16
+ options.prerenderRoutes
17
+ );
11
18
  }
12
19
  }
@@ -1,3 +1,4 @@
1
+ import PrerenderSPAPlugin from '@dreysolano/prerender-spa-plugin';
1
2
  import { join, basename } from 'path';
2
3
  import { Capsule } from '@teambit/isolator';
3
4
  import { Application, AppContext, DeployContext } from '@teambit/application';
@@ -12,7 +13,8 @@ export class ReactApp implements Application {
12
13
  readonly entry: string[],
13
14
  readonly portRange: number[],
14
15
  private reactEnv: ReactEnv,
15
- readonly deploy?: (context: DeployContext) => Promise<void>
16
+ readonly deploy?: (context: DeployContext) => Promise<void>,
17
+ readonly prerenderRoutes?: string[]
16
18
  ) {}
17
19
 
18
20
  applicationType = 'react';
@@ -61,6 +63,16 @@ export class ReactApp implements Application {
61
63
  const bundler: Bundler = await reactEnv.getBundler(bundlerContext, [
62
64
  (configMutator) => {
63
65
  configMutator.addTopLevel('output', { path: join(outputPath, 'public'), publicPath: `/` });
66
+ configMutator.addPlugin(
67
+ new PrerenderSPAPlugin({
68
+ staticDir: join(outputPath, 'public'),
69
+ routes: this.prerenderRoutes,
70
+ postProcess(renderedRoute) {
71
+ renderedRoute.outputPath = join(outputPath, 'public', `${renderedRoute.originalRoute}.html`);
72
+ return renderedRoute;
73
+ },
74
+ })
75
+ );
64
76
  return configMutator;
65
77
  },
66
78
  ]);