Skip to content

Commit cf27153

Browse files
authored
Merge pull request #23 from bitrise-io/separate-ssr-build
Separate SSR build into its own build-ssr.js script
2 parents 2cbcac3 + 6f886f2 commit cf27153

3 files changed

Lines changed: 70 additions & 48 deletions

File tree

build-ssr.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
const path = require('path');
2+
const webpack = require('webpack');
3+
4+
const webpackBuild = (config) =>
5+
new Promise((resolve, reject) => {
6+
webpack(config, (err, stats) => {
7+
if (err || stats.hasErrors()) {
8+
reject(stats);
9+
} else {
10+
resolve(stats);
11+
}
12+
});
13+
});
14+
15+
const buildPath = path.resolve(__dirname, 'build');
16+
const distPath = path.resolve(__dirname, 'dist');
17+
18+
const ssrWebpackConfig = {
19+
target: 'node',
20+
mode: 'production',
21+
entry: {
22+
integrations: path.resolve(__dirname, 'src/js/integrations/ssr.js'),
23+
},
24+
output: {
25+
path: buildPath,
26+
filename: '[name]-ssr.js',
27+
library: { type: 'commonjs2' },
28+
},
29+
resolve: {
30+
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
31+
},
32+
externals: ({ request }, callback) => {
33+
if (request && /^[a-zA-Z@]/.test(request)) {
34+
callback(null, `commonjs2 ${request}`);
35+
} else {
36+
callback();
37+
}
38+
},
39+
};
40+
41+
const build = async () => {
42+
/** @type {webpack.Stats} */
43+
let webpackSsrStats;
44+
try {
45+
webpackSsrStats = await webpackBuild(ssrWebpackConfig);
46+
} catch (error) {
47+
webpackSsrStats = error;
48+
}
49+
if (webpackSsrStats.hasErrors()) {
50+
process.stderr.write(`SSR Webpack build failed:\n${webpackSsrStats.toString({ colors: true })}\n\n`);
51+
throw new Error('SSR Webpack build failed');
52+
} else {
53+
process.stdout.write(
54+
`SSR Webpack build completed successfully:\n${webpackSsrStats.toString({ colors: true })}\n\n`,
55+
);
56+
}
57+
58+
// eslint-disable-next-line global-require
59+
const { render: renderIntegrations } = require('./build/integrations-ssr.js');
60+
await renderIntegrations({
61+
destination: distPath,
62+
templateHostname: 'bitrise.io',
63+
});
64+
};
65+
66+
build().catch((error) => {
67+
process.stderr.write(`SSR build failed: ${error.message}\n`);
68+
process.exit(1);
69+
});

build.js

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,6 @@ const webpackBuild = (config) =>
1515

1616
const { build: buildMaintenance } = require('./src/js/maintenance/build.js');
1717

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-zA-Z@]/.test(request)) {
36-
callback(null, `commonjs2 ${request}`);
37-
} else {
38-
callback();
39-
}
40-
},
41-
};
42-
4318
const build = async () => {
4419
const webpackConfig = webpackConfigBuilder('production');
4520

@@ -57,29 +32,6 @@ const build = async () => {
5732
process.stdout.write(`Webpack build completed successfully:\n${webpackStats.toString({ colors: true })}\n\n`);
5833
}
5934

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-
8335
// Build maintenance.html (depends on dist/404.js from webpack)
8436
await buildMaintenance({
8537
distPath: path.resolve(__dirname, webpackConfig.output.path),

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"scripts": {
3232
"dev": "node ./index.js",
3333
"build": "node ./build.js",
34+
"build:ssr": "node ./build-ssr.js",
3435
"build_changelog": "node ./src/js/changelog/build.js",
3536
"build_career_maps": "node ./src/js/career-maps/build.js",
3637
"build:navigation": "node ./src/js/bitrise-navigation/build.js ./dist/bitrise-navigation-loader.js",

0 commit comments

Comments
 (0)