diff --git a/template/gulp-tasks/build.js b/template/gulp-tasks/build.js index 294fd3c..abf1274 100644 --- a/template/gulp-tasks/build.js +++ b/template/gulp-tasks/build.js @@ -9,6 +9,7 @@ import babelify from 'babelify'; import modulesify from 'css-modulesify'; import source from 'vinyl-source-stream'; import buffer from 'vinyl-buffer'; +import {argv} from 'yargs'; import {dirs} from './config'; import {customSass} from './compilers'; @@ -21,7 +22,7 @@ gulp.task('build:test', () => gulp.src([ .pipe(sourcemaps.write()) .pipe(gulp.dest(dirs.buildTest))); -gulp.task('build:client', ['copy:client'], () => { +gulp.task('build:client', ['copy:client', 'copy:config:server'], () => { vueify.compiler.applyConfig({ sass: { includePaths: [ @@ -58,6 +59,18 @@ gulp.task('build:client', ['copy:client'], () => { }, }); + if (argv.production) { + b.transform(aliasify, { + replacements: { + '(.+)server/config.json$': path.resolve( + dirs.buildServer, + 'config.json', + ), + }, + verbose: true, + }); + } + return b.bundle() .pipe(source('bundle.js')) .pipe(buffer()) @@ -74,7 +87,7 @@ gulp.task('build:common', () => { .pipe(gulp.dest(dirs.buildCommon)); }); -gulp.task('build:server', ['copy:server'], () => { +gulp.task('build:server', ['copy:server', 'copy:config:server'], () => { return gulp.src(path.resolve(dirs.srcServer, '**/*.js')) .pipe(sourcemaps.init()) .pipe(babel()) diff --git a/template/gulp-tasks/config.js b/template/gulp-tasks/config.js index b89f791..61c5a89 100644 --- a/template/gulp-tasks/config.js +++ b/template/gulp-tasks/config.js @@ -15,3 +15,9 @@ dirs.testServer = path.resolve(dirs.test, 'server'); dirs.srcClient = path.resolve(dirs.root, 'client'); dirs.srcCommon = path.resolve(dirs.root, 'common'); dirs.srcServer = path.resolve(dirs.root, 'server'); + +// Set here production build settings +export const prod = { + host: '0.0.0.0', + port: 80, +}; diff --git a/template/gulp-tasks/copy.js b/template/gulp-tasks/copy.js index ec81b1e..2d5c0f9 100644 --- a/template/gulp-tasks/copy.js +++ b/template/gulp-tasks/copy.js @@ -1,7 +1,10 @@ /* eslint-disable arrow-body-style */ import gulp from 'gulp'; import path from 'path'; -import {dirs} from './config'; +import fs from 'fs'; +import {argv} from 'yargs'; +import {dirs, prod} from './config'; + gulp.task('copy:client:fa', () => { return gulp @@ -24,3 +27,27 @@ gulp.task('copy:server', () => { return gulp.src(`${dirs.srcServer}/**/*.json`) .pipe(gulp.dest(path.resolve(dirs.buildServer))); }); + +gulp.task('copy:config:server', ['copy:server'], (done) => { + if (argv.production) { + const configPath = path.resolve( + dirs.srcServer, + 'config.json' + ); + + fs.readFile(configPath, (err, data) => { + if (err) done(err); + + fs.writeFile( + path.resolve(dirs.buildServer, 'config.json'), + JSON.stringify({ + ...JSON.parse(data), + ...prod, + }), + done + ); + }); + } else { + done(); + } +});