Skip to content

Commit 8ba03cb

Browse files
committed
initial commit
1 parent 5ba4714 commit 8ba03cb

27 files changed

+19740
-0
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

Diff for: Dockerfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM node:10 AS ui-build
2+
WORKDIR /usr/src/app
3+
COPY my-app/ ./my-app/
4+
RUN cd my-app && npm install && npm run build
5+
6+
FROM node:10 AS server-build
7+
WORKDIR /root/
8+
COPY --from=ui-build /usr/src/app/my-app/build ./my-app/build
9+
COPY api/package*.json ./api/
10+
RUN cd api && npm install
11+
COPY api/server.js ./api/
12+
13+
EXPOSE 3080
14+
15+
CMD ["node", "./api/server.js"]

Diff for: api/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# react-nodejs-example
2+
Example Project demonstrating how to develop React application with Nodejs

Diff for: api/gulpfile.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
const { src, dest, series, parallel } = require('gulp');
2+
const del = require('del');
3+
const fs = require('fs');
4+
const zip = require('gulp-zip');
5+
const log = require('fancy-log');
6+
const webpack_stream = require('webpack-stream');
7+
const webpack_config = require('./webpack.config.js');
8+
var exec = require('child_process').exec;
9+
10+
const paths = {
11+
prod_build: '../prod-build',
12+
server_file_name: 'server.bundle.js',
13+
react_src: '../my-app/build/**/*',
14+
react_dist: '../prod-build/my-app/build',
15+
zipped_file_name: 'react-nodejs.zip'
16+
};
17+
18+
function clean() {
19+
log('removing the old files in the directory')
20+
return del('../prod-build/**', {force:true});
21+
}
22+
23+
function createProdBuildFolder() {
24+
25+
const dir = paths.prod_build;
26+
log(`Creating the folder if not exist ${dir}`)
27+
if(!fs.existsSync(dir)) {
28+
fs.mkdirSync(dir);
29+
log('📁 folder created:', dir);
30+
}
31+
32+
return Promise.resolve('the value is ignored');
33+
}
34+
35+
function buildReactCodeTask(cb) {
36+
log('building React code into the directory')
37+
return exec('cd ../my-app && npm run build', function (err, stdout, stderr) {
38+
log(stdout);
39+
log(stderr);
40+
cb(err);
41+
})
42+
}
43+
44+
function copyReactCodeTask() {
45+
log('copying React code into the directory')
46+
return src(`${paths.react_src}`)
47+
.pipe(dest(`${paths.react_dist}`));
48+
}
49+
50+
function copyNodeJSCodeTask() {
51+
log('building and copying server code into the directory')
52+
return webpack_stream(webpack_config)
53+
.pipe(dest(`${paths.prod_build}`))
54+
}
55+
56+
function zippingTask() {
57+
log('zipping the code ')
58+
return src(`${paths.prod_build}/**`)
59+
.pipe(zip(`${paths.zipped_file_name}`))
60+
.pipe(dest(`${paths.prod_build}`))
61+
}
62+
63+
exports.default = series(
64+
clean,
65+
createProdBuildFolder,
66+
buildReactCodeTask,
67+
parallel(copyReactCodeTask, copyNodeJSCodeTask),
68+
zippingTask
69+
);

0 commit comments

Comments
 (0)