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