@teambit/react 0.0.704 → 0.0.705

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.
Files changed (34) hide show
  1. package/apps/web/plugins/prerender.ts +7 -2
  2. package/apps/web/react-app-options.ts +21 -4
  3. package/apps/web/react.app-type.ts +1 -1
  4. package/apps/web/react.application.ts +58 -12
  5. package/artifacts/env-template/public/{694.js → 101.js} +10 -2
  6. package/artifacts/env-template/public/{114.js → 293.js} +3 -3
  7. package/artifacts/env-template/public/677.js +14 -2
  8. package/artifacts/env-template/public/750.js +6 -2
  9. package/artifacts/env-template/public/793.js +92 -36
  10. package/artifacts/env-template/public/assets-manifest.json +13 -13
  11. package/artifacts/env-template/public/{compositions.f2d331a862a1e8029cb5.js → compositions.4e009a6207acde247ba8.js} +1 -1
  12. package/artifacts/env-template/public/compositions.html +1 -1
  13. package/artifacts/env-template/public/{overview.34791a2a44b79b4bee81.js → overview.c393efcf635e7c48388f.js} +1 -1
  14. package/artifacts/env-template/public/overview.html +1 -1
  15. package/artifacts/env-template/public/{preview-root.94e10fd37290be85b239.js → preview-root.6aa001a89a7eb9c4eef3.js} +1 -1
  16. package/artifacts/env-template/public/service-worker.js +1 -1
  17. package/artifacts/env-template/public/static/css/793.ebb74038.css +1 -0
  18. package/artifacts/preview/teambit_react_react-preview.js +2 -2
  19. package/{compositions-1649388249695.js → compositions-1649474602488.js} +0 -0
  20. package/dist/apps/web/plugins/prerender.d.ts +2 -1
  21. package/dist/apps/web/plugins/prerender.js +19 -3
  22. package/dist/apps/web/plugins/prerender.js.map +1 -1
  23. package/dist/apps/web/react-app-options.d.ts +27 -4
  24. package/dist/apps/web/react.app-type.js +1 -3
  25. package/dist/apps/web/react.app-type.js.map +1 -1
  26. package/dist/apps/web/react.application.d.ts +4 -2
  27. package/dist/apps/web/react.application.js +56 -11
  28. package/dist/apps/web/react.application.js.map +1 -1
  29. package/{overview-1649388249695.js → overview-1649474602488.js} +0 -0
  30. package/package-tar/teambit-react-0.0.705.tgz +0 -0
  31. package/package.json +30 -30
  32. package/{preview-1649388249695.js → preview-1649474602488.js} +2 -2
  33. package/artifacts/env-template/public/static/css/793.fecb3731.css +0 -1
  34. package/package-tar/teambit-react-0.0.704.tgz +0 -0
@@ -1,13 +1,18 @@
1
1
  import { join } from 'path';
2
2
  import PrerenderSPAPlugin from '@dreysolano/prerender-spa-plugin';
3
+ import { ReactAppPrerenderOptions } from '../react-app-options';
3
4
 
4
- export const prerenderSPAPlugin = (prerenderRoutes: string[], staticDir: string) => {
5
+ export const prerenderSPAPlugin = (prerender: ReactAppPrerenderOptions, staticDir: string) => {
5
6
  return new PrerenderSPAPlugin({
6
7
  staticDir,
7
- routes: prerenderRoutes,
8
+ routes: prerender?.routes,
8
9
  postProcess(renderedRoute: any) {
10
+ if (prerender.postProcess) return prerender.postProcess(renderedRoute, staticDir);
9
11
  renderedRoute.outputPath = join(staticDir, `${renderedRoute.originalRoute}.html`);
10
12
  return renderedRoute;
11
13
  },
14
+ server: {
15
+ ...prerender?.server,
16
+ },
12
17
  });
13
18
  };
@@ -3,6 +3,23 @@ import { WebpackConfigTransformer } from '@teambit/webpack';
3
3
 
4
4
  import { ReactDeployContext } from './deploy-context';
5
5
 
6
+ export type ReactAppPrerenderOptions = {
7
+ /**
8
+ * routes to prerender
9
+ */
10
+ routes: string[];
11
+ /**
12
+ * the proxy server you want the prerender headless browser to run on
13
+ */
14
+
15
+ server?: { proxy: { [key: string]: { target: 'http://localhost:8000/'; pathRewrite: { [key: string]: string } } } };
16
+
17
+ /**
18
+ * Post processing of the prerendered html. This is useful for adding meta tags to the html or changing the file name.
19
+ */
20
+ postProcess?: (prerenderRoute: string, staticDir: string) => string;
21
+ };
22
+
6
23
  export type ReactAppOptions = {
7
24
  /**
8
25
  * name of the application.
@@ -36,11 +53,11 @@ export type ReactAppOptions = {
36
53
 
37
54
  /**
38
55
  * decide whether to prerender your app. accepts an array of routes. if none, prerender would not apply.
39
- * e.g ['/plugins', '/learn', '/docs/quick-start]
56
+ * e.g ['/plugins', '/learn', '/docs/quick-start]
57
+ * You can also pass a configuration for the proxy, please refer here: https://github.com/webpack/docs/wiki/webpack-dev-server#proxy
58
+ *
40
59
  */
41
- prerender?: {
42
- routes?: string[];
43
- };
60
+ prerender?: ReactAppPrerenderOptions;
44
61
 
45
62
  /**
46
63
  * deploy function.
@@ -12,7 +12,7 @@ export class ReactAppType implements ApplicationType<ReactAppOptions> {
12
12
  options.entry,
13
13
  options.portRange || [3000, 4000],
14
14
  this.reactEnv,
15
- options.prerender?.routes,
15
+ options.prerender,
16
16
  options.bundler,
17
17
  options.devServer,
18
18
  options.webpackTransformers,
@@ -8,6 +8,7 @@ import { WebpackConfigTransformer } from '@teambit/webpack';
8
8
  import { ReactEnv } from '../../react.env';
9
9
  import { prerenderSPAPlugin } from './plugins';
10
10
  import { ReactAppBuildResult } from './react-build-result';
11
+ import { ReactAppPrerenderOptions } from './react-app-options';
11
12
  import { html } from '../../webpack';
12
13
  import { ReactDeployContext } from '.';
13
14
 
@@ -17,7 +18,7 @@ export class ReactApp implements Application {
17
18
  readonly entry: string[],
18
19
  readonly portRange: number[],
19
20
  private reactEnv: ReactEnv,
20
- readonly prerenderRoutes?: string[],
21
+ readonly prerender?: ReactAppPrerenderOptions,
21
22
  readonly bundler?: Bundler,
22
23
  readonly devServer?: DevServer,
23
24
  readonly transformers?: WebpackConfigTransformer[],
@@ -102,28 +103,73 @@ export class ReactApp implements Application {
102
103
 
103
104
  const defaultTransformer: WebpackConfigTransformer = (configMutator) => {
104
105
  const config = configMutator.addTopLevel('output', { path: staticDir, publicPath: `/` });
105
- if (this.prerenderRoutes) config.addPlugin(prerenderSPAPlugin(this.prerenderRoutes, staticDir));
106
+ if (this.prerender) config.addPlugin(prerenderSPAPlugin(this.prerender, staticDir));
106
107
  if (config.raw.optimization?.minimizer) {
107
108
  remove(config.raw.optimization?.minimizer, (minimizer) => {
108
109
  return minimizer.constructor.name === 'TerserPlugin';
109
110
  });
110
- config.raw.optimization?.minimizer.push(
111
- new TerserPlugin({
112
- minify: TerserPlugin.esbuildMinify,
113
- // `terserOptions` options will be passed to `esbuild`
114
- // Link to options - https://esbuild.github.io/api/#minify
115
- terserOptions: {
116
- minify: true,
117
- },
118
- })
119
- );
111
+
112
+ config.raw.optimization?.minimizer.push(this.getESBuildConfig());
120
113
  }
114
+
121
115
  return config;
122
116
  };
123
117
  const transformers = [defaultTransformer, ...(this.transformers ?? [])];
124
118
  const bundler: Bundler = await reactEnv.getBundler(bundlerContext, transformers);
125
119
  return bundler;
126
120
  }
121
+ private getESBuildConfig = (isPrerendering = this.prerender) => {
122
+ // We don't want to use esbuild in case of prerendering since the headless browser puppeteer doesn't support
123
+ // the output of esbuild
124
+
125
+ if (isPrerendering) {
126
+ return new TerserPlugin({
127
+ extractComments: false,
128
+ terserOptions: {
129
+ parse: {
130
+ // We want terser to parse ecma 8 code. However, we don't want it
131
+ // to apply any minification steps that turns valid ecma 5 code
132
+ // into invalid ecma 5 code. This is why the 'compress' and 'output'
133
+ // sections only apply transformations that are ecma 5 safe
134
+ // https://github.com/facebook/create-react-app/pull/4234
135
+ ecma: 8,
136
+ },
137
+ compress: {
138
+ ecma: 5,
139
+ warnings: false,
140
+ // Disabled because of an issue with Uglify breaking seemingly valid code:
141
+ // https://github.com/facebook/create-react-app/issues/2376
142
+ // Pending further investigation:
143
+ // https://github.com/mishoo/UglifyJS2/issues/2011
144
+ comparisons: false,
145
+ // Disabled because of an issue with Terser breaking valid code:
146
+ // https://github.com/facebook/create-react-app/issues/5250
147
+ // Pending further investigation:
148
+ // https://github.com/terser-js/terser/issues/120
149
+ inline: 2,
150
+ },
151
+ mangle: {
152
+ safari10: true,
153
+ },
154
+ output: {
155
+ ecma: 5,
156
+ comments: false,
157
+ // Turned on because emoji and regex is not minified properly using default
158
+ // https://github.com/facebook/create-react-app/issues/2488
159
+ ascii_only: true,
160
+ },
161
+ },
162
+ });
163
+ }
164
+ return new TerserPlugin({
165
+ minify: TerserPlugin.esbuildMinify,
166
+ // `terserOptions` options will be passed to `esbuild`
167
+ // Link to options - https://esbuild.github.io/api/#minify
168
+ terserOptions: {
169
+ minify: true,
170
+ },
171
+ });
172
+ };
127
173
 
128
174
  private getPublicDir() {
129
175
  return join(this.applicationType, this.name);