Skip to content

Commit 661ee6f

Browse files
committed
feat(build): add copy:config:server
1 parent 49f48c5 commit 661ee6f

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

template/gulp-tasks/build.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import babelify from 'babelify';
99
import modulesify from 'css-modulesify';
1010
import source from 'vinyl-source-stream';
1111
import buffer from 'vinyl-buffer';
12+
import {argv} from 'yargs';
1213
import {dirs} from './config';
1314
import {customSass} from './compilers';
1415

@@ -21,7 +22,7 @@ gulp.task('build:test', () => gulp.src([
2122
.pipe(sourcemaps.write())
2223
.pipe(gulp.dest(dirs.buildTest)));
2324

24-
gulp.task('build:client', ['copy:client'], () => {
25+
gulp.task('build:client', ['copy:client', 'copy:config:server'], () => {
2526
vueify.compiler.applyConfig({
2627
sass: {
2728
includePaths: [
@@ -58,6 +59,18 @@ gulp.task('build:client', ['copy:client'], () => {
5859
},
5960
});
6061

62+
if (argv.production) {
63+
b.transform(aliasify, {
64+
replacements: {
65+
'(.+)server/config.json$': path.resolve(
66+
dirs.buildServer,
67+
'config.json',
68+
),
69+
},
70+
verbose: true,
71+
});
72+
}
73+
6174
return b.bundle()
6275
.pipe(source('bundle.js'))
6376
.pipe(buffer())
@@ -74,7 +87,7 @@ gulp.task('build:common', () => {
7487
.pipe(gulp.dest(dirs.buildCommon));
7588
});
7689

77-
gulp.task('build:server', ['copy:server'], () => {
90+
gulp.task('build:server', ['copy:server', 'copy:config:server'], () => {
7891
return gulp.src(path.resolve(dirs.srcServer, '**/*.js'))
7992
.pipe(sourcemaps.init())
8093
.pipe(babel())

template/gulp-tasks/config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@ dirs.testServer = path.resolve(dirs.test, 'server');
1515
dirs.srcClient = path.resolve(dirs.root, 'client');
1616
dirs.srcCommon = path.resolve(dirs.root, 'common');
1717
dirs.srcServer = path.resolve(dirs.root, 'server');
18+
19+
// Set here production build settings
20+
export const prod = {
21+
host: '0.0.0.0',
22+
port: 80,
23+
};

template/gulp-tasks/copy.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
/* eslint-disable arrow-body-style */
22
import gulp from 'gulp';
33
import path from 'path';
4-
import {dirs} from './config';
4+
import fs from 'fs';
5+
import {argv} from 'yargs';
6+
import {dirs, prod} from './config';
7+
58

69
gulp.task('copy:client:fa', () => {
710
return gulp
@@ -24,3 +27,27 @@ gulp.task('copy:server', () => {
2427
return gulp.src(`${dirs.srcServer}/**/*.json`)
2528
.pipe(gulp.dest(path.resolve(dirs.buildServer)));
2629
});
30+
31+
gulp.task('copy:config:server', ['copy:server'], (done) => {
32+
if (argv.production) {
33+
const configPath = path.resolve(
34+
dirs.srcServer,
35+
'config.json'
36+
);
37+
38+
fs.readFile(configPath, (err, data) => {
39+
if (err) done(err);
40+
41+
fs.writeFile(
42+
path.resolve(dirs.buildServer, 'config.json'),
43+
JSON.stringify({
44+
...JSON.parse(data),
45+
...prod,
46+
}),
47+
done
48+
);
49+
});
50+
} else {
51+
done();
52+
}
53+
});

0 commit comments

Comments
 (0)