Skip to content

Commit

Permalink
Improve speed of building
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsum committed Jan 25, 2017
1 parent f136611 commit dd7e74a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

#### 1.0.13
- Add Production configuration for webpack @see https://github.com/rambler-digital-solutions/rship/issues/17
- Improve speed of building app

#### 1.0.12
- Remove unuseable lines of code
- Update dependencies
Expand Down
35 changes: 29 additions & 6 deletions cli/commands/subcommands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,25 @@ module.exports = function(program, config = {}) {
// if config has minify option
if (config.build.minify) {
let options = { compress: { warnings: true } };
let defineOptions = { 'process.env': { 'NODE_ENV': JSON.stringify('production') } };

let minifyServer = new webpack.optimize.UglifyJsPlugin(options);
let minifyClient = new webpack.optimize.UglifyJsPlugin(options);

let defineServerProduction = new webpack.DefinePlugin(defineOptions);
let defineClientProduction = new webpack.DefinePlugin(defineOptions);

// check plugins block
serverConfig && !serverConfig.plugins ? serverConfig.plugins = [] : null;
clientConfig && !clientConfig.plugins ? clientConfig.plugins = [] : null;

// push minify plugins to config
serverConfig.plugins.push(minifyServer);
clientConfig.plugins.push(minifyClient);

// push define production env
serverConfig.plugins.push(defineServerProduction);
clientConfig.plugins.push(defineClientProduction);
}

// prepare separated webpack instances
Expand All @@ -58,6 +69,8 @@ module.exports = function(program, config = {}) {
// prepare folders for compiling
utils.exec(`rm -rf ${dir}/dist`, { cwd: cwd }, null, true);
utils.exec(`mkdir ${dir}/dist`, { cwd: cwd }, null, true);
utils.exec(`mkdir ${dir}/dist/server`, { cwd: cwd }, null, true);
utils.exec(`mkdir ${dir}/dist/client`, { cwd: cwd }, null, true);

let Server = new Promise((resolve, reject) => {
serverCompiler.run((err, stat) => {
Expand All @@ -77,21 +90,31 @@ module.exports = function(program, config = {}) {
});
});

// status checked
Server.then(() => logger('SHIP: Webpack.Server:Success', 'green'))
Client.then(() => logger('SHIP: Webpack.Client:Success', 'green'))

// copy node_modules
let Copy = new Promise((resolve, reject) => {
try {
utils.exec(`mkdir ${dir}/dist/server`, { cwd: cwd }, null, true);
utils.exec(`cp -r ${dir}/node_modules ${dir}/dist/server/node_modules/`, { cwd: cwd }, null, true);
utils.exec(`cp ${dir}/package.json ${dir}/dist/server`, { cwd: cwd }, null, true);
resolve();
} catch (err) {
reject(err);
}
});

// status checked
Server.then(() => logger('SHIP: Webpack.Server:Success', 'green'));
Client.then(() => logger('SHIP: Webpack.Client:Success', 'green'));

// lets install production dependencies
Copy.then(() => {
utils.exec(
utils.makeCommand(cwd, 'install --production', [], ''), // command
{ cwd: `${dir}/dist/server` }, // options
null, // no callback
false, // no sync
true // print stdout
);
});

// wrap steps to promise
Promise.all([Server, Client, Copy])
.then(() => logger('SHIP: Done', 'green'))
Expand Down
1 change: 0 additions & 1 deletion cli/commands/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ const checkInstance = (dir) => {
};

/**
*
* @param {[type]} cwd [description]
* @param {String} command [description]
* @param {Array} packages [description]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rship",
"version": "1.0.12",
"version": "1.0.13",
"description": "Ecosystem for building isomorphic web applications",
"main": "./cli/index.js",
"bin": {
Expand Down

0 comments on commit dd7e74a

Please sign in to comment.