1+ const path = require ( 'path' ) ;
12const webpack = require ( 'webpack' ) ;
23const webpackConfigBuilder = require ( './webpack.config.js' ) ;
34
@@ -14,11 +15,38 @@ const webpackBuild = (config) =>
1415
1516const { build : buildMaintenance } = require ( './src/js/maintenance/build.js' ) ;
1617
18+ const buildPath = path . resolve ( __dirname , 'build' ) ;
19+
20+ const ssrWebpackConfig = {
21+ target : 'node' ,
22+ mode : 'production' ,
23+ entry : {
24+ integrations : path . resolve ( __dirname , 'src/js/integrations/ssr.js' ) ,
25+ } ,
26+ output : {
27+ path : buildPath ,
28+ filename : '[name]-ssr.js' ,
29+ library : { type : 'commonjs2' } ,
30+ } ,
31+ resolve : {
32+ modules : [ path . resolve ( __dirname , 'src' ) , 'node_modules' ] ,
33+ } ,
34+ externals : ( { request } , callback ) => {
35+ if ( request && / ^ [ a - z A - Z @ ] / . test ( request ) ) {
36+ callback ( null , `commonjs2 ${ request } ` ) ;
37+ } else {
38+ callback ( ) ;
39+ }
40+ } ,
41+ } ;
42+
1743const build = async ( ) => {
44+ const webpackConfig = webpackConfigBuilder ( 'production' ) ;
45+
1846 // Build project with Webpack
1947 let webpackStats ;
2048 try {
21- webpackStats = await webpackBuild ( webpackConfigBuilder ( 'production' ) ) ;
49+ webpackStats = await webpackBuild ( webpackConfig ) ;
2250 } catch ( error ) {
2351 webpackStats = error ;
2452 }
@@ -29,9 +57,34 @@ const build = async () => {
2957 process . stdout . write ( `Webpack build completed successfully:\n${ webpackStats . toString ( { colors : true } ) } \n\n` ) ;
3058 }
3159
60+ /** @type {webpack.Stats } */
61+ let webpackSsrStats ;
62+ try {
63+ webpackSsrStats = await webpackBuild ( ssrWebpackConfig ) ;
64+ } catch ( error ) {
65+ webpackSsrStats = error ;
66+ }
67+ if ( webpackSsrStats . hasErrors ( ) ) {
68+ process . stderr . write ( `SSR Webpack build failed:\n${ webpackSsrStats . toString ( { colors : true } ) } \n\n` ) ;
69+ throw new Error ( 'SSR Webpack build failed' ) ;
70+ } else {
71+ process . stdout . write (
72+ `SSR Webpack build completed successfully:\n${ webpackSsrStats . toString ( { colors : true } ) } \n\n` ,
73+ ) ;
74+ }
75+
76+ // eslint-disable-next-line global-require
77+ const { render : renderIntegrations } = require ( './build/integrations-ssr.js' ) ;
78+ await renderIntegrations ( {
79+ destination : path . resolve ( __dirname , webpackConfig . output . path ) ,
80+ templateHostname : 'bitrise.io' ,
81+ } ) ;
82+
3283 // Build maintenance.html (depends on dist/404.js from webpack)
33- await buildMaintenance ( ) ;
34- process . stdout . write ( 'Maintenance page build completed successfully.\n\n' ) ;
84+ await buildMaintenance ( {
85+ distPath : path . resolve ( __dirname , webpackConfig . output . path ) ,
86+ srcPath : path . resolve ( __dirname , 'src' ) ,
87+ } ) ;
3588} ;
3689
3790build ( ) . catch ( ( error ) => {
0 commit comments