Commit d78202018a8b5d18683302ccab5dcd18ed0f32bd

Authored by Igor Kulikov
Committed by GitHub
2 parents 90c3a2b5 e9e10d74

Merge pull request #1441 from vparomskiy/master

 cache webpack resources and run loaders in concurrent mode
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 ], 11 ],
12 "scripts": { 12 "scripts": {
13 "start": "babel-node --max_old_space_size=4096 server.js", 13 "start": "babel-node --max_old_space_size=4096 server.js",
14 - "build": "cross-env NODE_ENV=production webpack -p" 14 + "build": "cross-env NODE_ENV=production webpack"
15 }, 15 },
16 "dependencies": { 16 "dependencies": {
17 "@flowjs/ng-flow": "^2.7.1", 17 "@flowjs/ng-flow": "^2.7.1",
@@ -136,7 +136,9 @@ @@ -136,7 +136,9 @@
136 "webpack-dev-middleware": "^1.6.1", 136 "webpack-dev-middleware": "^1.6.1",
137 "webpack-dev-server": "^1.15.1", 137 "webpack-dev-server": "^1.15.1",
138 "webpack-hot-middleware": "^2.12.2", 138 "webpack-hot-middleware": "^2.12.2",
139 - "webpack-material-design-icons": "^0.1.0" 139 + "webpack-material-design-icons": "^0.1.0",
  140 + "uglifyjs-webpack-plugin": "^1.3.0",
  141 + "happypack": "^5.0.1"
140 }, 142 },
141 "engine": "node >= 5.9.0", 143 "engine": "node >= 5.9.0",
142 "nyc": { 144 "nyc": {
@@ -18,13 +18,16 @@ @@ -18,13 +18,16 @@
18 const HtmlWebpackPlugin = require('html-webpack-plugin'); 18 const HtmlWebpackPlugin = require('html-webpack-plugin');
19 const ExtractTextPlugin = require('extract-text-webpack-plugin'); 19 const ExtractTextPlugin = require('extract-text-webpack-plugin');
20 const CopyWebpackPlugin = require('copy-webpack-plugin'); 20 const CopyWebpackPlugin = require('copy-webpack-plugin');
21 -const StyleLintPlugin = require('stylelint-webpack-plugin') 21 +const StyleLintPlugin = require('stylelint-webpack-plugin');
22 22
23 const webpack = require('webpack'); 23 const webpack = require('webpack');
24 const path = require('path'); 24 const path = require('path');
25 const dirTree = require('directory-tree'); 25 const dirTree = require('directory-tree');
26 const jsonminify = require("jsonminify"); 26 const jsonminify = require("jsonminify");
27 27
  28 +const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
  29 +const HappyPack = require('happypack');
  30 +
28 const PUBLIC_RESOURCE_PATH = '/'; 31 const PUBLIC_RESOURCE_PATH = '/';
29 32
30 var langs = []; 33 var langs = [];
@@ -34,6 +37,9 @@ dirTree('./src/app/locale/', {extensions:/\.json$/}, (item) => { @@ -34,6 +37,9 @@ dirTree('./src/app/locale/', {extensions:/\.json$/}, (item) => {
34 langs.push(item.name.slice(item.name.lastIndexOf('-') + 1, -5)); 37 langs.push(item.name.slice(item.name.lastIndexOf('-') + 1, -5));
35 }); 38 });
36 39
  40 +
  41 +var happyThreadPool = HappyPack.ThreadPool({ size: 3 });
  42 +
37 /* devtool: 'cheap-module-eval-source-map', */ 43 /* devtool: 'cheap-module-eval-source-map', */
38 44
39 module.exports = { 45 module.exports = {
@@ -93,6 +99,25 @@ module.exports = { @@ -93,6 +99,25 @@ module.exports = {
93 PUBLIC_PATH: JSON.stringify(PUBLIC_RESOURCE_PATH), 99 PUBLIC_PATH: JSON.stringify(PUBLIC_RESOURCE_PATH),
94 SUPPORTED_LANGS: JSON.stringify(langs) 100 SUPPORTED_LANGS: JSON.stringify(langs)
95 }), 101 }),
  102 + new UglifyJsPlugin({
  103 + cache: true,
  104 + parallel: true
  105 + }),
  106 + new HappyPack({
  107 + threadPool: happyThreadPool,
  108 + id: 'cached-babel',
  109 + loaders: ["babel-loader?cacheDirectory=true"]
  110 + }),
  111 + new HappyPack({
  112 + threadPool: happyThreadPool,
  113 + id: 'eslint',
  114 + loaders: ["eslint-loader?{parser: 'babel-eslint'}"]
  115 + }),
  116 + new HappyPack({
  117 + threadPool: happyThreadPool,
  118 + id: 'ng-annotate-and-cached-babel-loader',
  119 + loaders: ['ng-annotate', 'babel-loader?cacheDirectory=true']
  120 + })
96 ], 121 ],
97 node: { 122 node: {
98 tls: "empty", 123 tls: "empty",
@@ -102,19 +127,19 @@ module.exports = { @@ -102,19 +127,19 @@ module.exports = {
102 loaders: [ 127 loaders: [
103 { 128 {
104 test: /\.jsx$/, 129 test: /\.jsx$/,
105 - loader: 'babel', 130 + loader: 'happypack/loader?id=cached-babel',
106 exclude: /node_modules/, 131 exclude: /node_modules/,
107 include: __dirname, 132 include: __dirname,
108 }, 133 },
109 { 134 {
110 test: /\.js$/, 135 test: /\.js$/,
111 - loaders: ['ng-annotate', 'babel'], 136 + loaders: ['happypack/loader?id=ng-annotate-and-cached-babel-loader'],
112 exclude: /node_modules/, 137 exclude: /node_modules/,
113 include: __dirname, 138 include: __dirname,
114 }, 139 },
115 { 140 {
116 test: /\.js$/, 141 test: /\.js$/,
117 - loader: "eslint-loader?{parser: 'babel-eslint'}", 142 + loader: 'happypack/loader?id=eslint',
118 exclude: /node_modules|vendor/, 143 exclude: /node_modules|vendor/,
119 include: __dirname, 144 include: __dirname,
120 }, 145 },
@@ -23,6 +23,8 @@ const webpack = require('webpack'); @@ -23,6 +23,8 @@ const webpack = require('webpack');
23 const path = require('path'); 23 const path = require('path');
24 const dirTree = require('directory-tree'); 24 const dirTree = require('directory-tree');
25 const jsonminify = require("jsonminify"); 25 const jsonminify = require("jsonminify");
  26 +const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
  27 +const HappyPack = require('happypack');
26 28
27 const PUBLIC_RESOURCE_PATH = '/static/'; 29 const PUBLIC_RESOURCE_PATH = '/static/';
28 30
@@ -33,6 +35,8 @@ dirTree('./src/app/locale/', {extensions:/\.json$/}, (item) => { @@ -33,6 +35,8 @@ dirTree('./src/app/locale/', {extensions:/\.json$/}, (item) => {
33 langs.push(item.name.slice(item.name.lastIndexOf('-') + 1, -5)); 35 langs.push(item.name.slice(item.name.lastIndexOf('-') + 1, -5));
34 }); 36 });
35 37
  38 +var happyThreadPool = HappyPack.ThreadPool({ size: 3 });
  39 +
36 module.exports = { 40 module.exports = {
37 devtool: 'source-map', 41 devtool: 'source-map',
38 entry: [ 42 entry: [
@@ -95,6 +99,25 @@ module.exports = { @@ -95,6 +99,25 @@ module.exports = {
95 test: /\.js$|\.css$|\.svg$|\.ttf$|\.woff$|\.woff2|\.eot$\.json$/, 99 test: /\.js$|\.css$|\.svg$|\.ttf$|\.woff$|\.woff2|\.eot$\.json$/,
96 threshold: 10240, 100 threshold: 10240,
97 minRatio: 0.8 101 minRatio: 0.8
  102 + }),
  103 + new UglifyJsPlugin({
  104 + cache: true,
  105 + parallel: true
  106 + }),
  107 + new HappyPack({
  108 + threadPool: happyThreadPool,
  109 + id: 'cached-babel',
  110 + loaders: ["babel-loader?cacheDirectory=true"]
  111 + }),
  112 + new HappyPack({
  113 + threadPool: happyThreadPool,
  114 + id: 'eslint',
  115 + loaders: ["eslint-loader?{parser: 'babel-eslint'}"]
  116 + }),
  117 + new HappyPack({
  118 + threadPool: happyThreadPool,
  119 + id: 'ng-annotate-and-cached-babel-loader',
  120 + loaders: ['ng-annotate', 'babel-loader?cacheDirectory=true']
98 }) 121 })
99 ], 122 ],
100 node: { 123 node: {
@@ -105,19 +128,20 @@ module.exports = { @@ -105,19 +128,20 @@ module.exports = {
105 loaders: [ 128 loaders: [
106 { 129 {
107 test: /\.jsx$/, 130 test: /\.jsx$/,
108 - loader: 'babel', 131 + loader: 'happypack/loader?id=cached-babel',
109 exclude: /node_modules/, 132 exclude: /node_modules/,
110 include: __dirname, 133 include: __dirname,
111 }, 134 },
112 { 135 {
113 test: /\.js$/, 136 test: /\.js$/,
114 - loaders: ['ng-annotate', 'babel'], 137 + loaders: ['happypack/loader?id=ng-annotate-and-cached-babel-loader'],
115 exclude: /node_modules/, 138 exclude: /node_modules/,
116 include: __dirname, 139 include: __dirname,
117 }, 140 },
118 { 141 {
119 test: /\.js$/, 142 test: /\.js$/,
120 - loader: "eslint-loader?{parser: 'babel-eslint'}", 143 + loaders: ['happypack/loader?id=eslint'],
  144 + // loader: "eslint-loader?{parser: 'babel-eslint'}",
121 exclude: /node_modules|vendor/, 145 exclude: /node_modules|vendor/,
122 include: __dirname, 146 include: __dirname,
123 }, 147 },