thingsboard-aplcache

Merge pull request #1441 from vparomskiy/master cache webpack

1/31/2019 4:08:57 PM

Changes

ui/package.json 6(+4 -2)

Details

ui/package.json 6(+4 -2)

diff --git a/ui/package.json b/ui/package.json
index 24f4bf6..a9ec3e0 100644
--- a/ui/package.json
+++ b/ui/package.json
@@ -11,7 +11,7 @@
   ],
   "scripts": {
     "start": "babel-node --max_old_space_size=4096 server.js",
-    "build": "cross-env NODE_ENV=production webpack -p"
+    "build": "cross-env NODE_ENV=production webpack"
   },
   "dependencies": {
     "@flowjs/ng-flow": "^2.7.1",
@@ -136,7 +136,9 @@
     "webpack-dev-middleware": "^1.6.1",
     "webpack-dev-server": "^1.15.1",
     "webpack-hot-middleware": "^2.12.2",
-    "webpack-material-design-icons": "^0.1.0"
+    "webpack-material-design-icons": "^0.1.0",
+    "uglifyjs-webpack-plugin": "^1.3.0",
+    "happypack": "^5.0.1"
   },
   "engine": "node >= 5.9.0",
   "nyc": {
diff --git a/ui/webpack.config.dev.js b/ui/webpack.config.dev.js
index cfff811..bea9275 100644
--- a/ui/webpack.config.dev.js
+++ b/ui/webpack.config.dev.js
@@ -18,13 +18,16 @@
 const HtmlWebpackPlugin = require('html-webpack-plugin');
 const ExtractTextPlugin = require('extract-text-webpack-plugin');
 const CopyWebpackPlugin = require('copy-webpack-plugin');
-const StyleLintPlugin = require('stylelint-webpack-plugin')
+const StyleLintPlugin = require('stylelint-webpack-plugin');
 
 const webpack = require('webpack');
 const path = require('path');
 const dirTree = require('directory-tree');
 const jsonminify = require("jsonminify");
 
+const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
+const HappyPack = require('happypack');
+
 const PUBLIC_RESOURCE_PATH = '/';
 
 var langs = [];
@@ -34,6 +37,9 @@ dirTree('./src/app/locale/', {extensions:/\.json$/}, (item) => {
     langs.push(item.name.slice(item.name.lastIndexOf('-') + 1, -5));
 });
 
+
+var happyThreadPool = HappyPack.ThreadPool({ size: 3 });
+
 /* devtool: 'cheap-module-eval-source-map', */
 
 module.exports = {
@@ -93,6 +99,25 @@ module.exports = {
             PUBLIC_PATH: JSON.stringify(PUBLIC_RESOURCE_PATH),
             SUPPORTED_LANGS: JSON.stringify(langs)
         }),
+        new UglifyJsPlugin({
+            cache: true,
+            parallel: true
+        }),
+        new HappyPack({
+            threadPool: happyThreadPool,
+            id: 'cached-babel',
+            loaders: ["babel-loader?cacheDirectory=true"]
+        }),
+        new HappyPack({
+            threadPool: happyThreadPool,
+            id: 'eslint',
+            loaders: ["eslint-loader?{parser: 'babel-eslint'}"]
+        }),
+        new HappyPack({
+            threadPool: happyThreadPool,
+            id: 'ng-annotate-and-cached-babel-loader',
+            loaders: ['ng-annotate', 'babel-loader?cacheDirectory=true']
+        })
     ],
     node: {
         tls: "empty",
@@ -102,19 +127,19 @@ module.exports = {
         loaders: [
             {
                 test: /\.jsx$/,
-                loader: 'babel',
+                loader: 'happypack/loader?id=cached-babel',
                 exclude: /node_modules/,
                 include: __dirname,
             },
             {
                 test: /\.js$/,
-                loaders: ['ng-annotate', 'babel'],
+                loaders: ['happypack/loader?id=ng-annotate-and-cached-babel-loader'],
                 exclude: /node_modules/,
                 include: __dirname,
             },
             {
                 test: /\.js$/,
-                loader: "eslint-loader?{parser: 'babel-eslint'}",
+                loader: 'happypack/loader?id=eslint',
                 exclude: /node_modules|vendor/,
                 include: __dirname,
             },
diff --git a/ui/webpack.config.prod.js b/ui/webpack.config.prod.js
index a442590..c0809fe 100644
--- a/ui/webpack.config.prod.js
+++ b/ui/webpack.config.prod.js
@@ -23,6 +23,8 @@ const webpack = require('webpack');
 const path = require('path');
 const dirTree = require('directory-tree');
 const jsonminify = require("jsonminify");
+const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
+const HappyPack = require('happypack');
 
 const PUBLIC_RESOURCE_PATH = '/static/';
 
@@ -33,6 +35,8 @@ dirTree('./src/app/locale/', {extensions:/\.json$/}, (item) => {
     langs.push(item.name.slice(item.name.lastIndexOf('-') + 1, -5));
 });
 
+var happyThreadPool = HappyPack.ThreadPool({ size: 3 });
+
 module.exports = {
     devtool: 'source-map',
     entry: [
@@ -95,6 +99,25 @@ module.exports = {
             test: /\.js$|\.css$|\.svg$|\.ttf$|\.woff$|\.woff2|\.eot$\.json$/,
             threshold: 10240,
             minRatio: 0.8
+        }),
+        new UglifyJsPlugin({
+            cache: true,
+            parallel: true
+        }),
+        new HappyPack({
+            threadPool: happyThreadPool,
+            id: 'cached-babel',
+            loaders: ["babel-loader?cacheDirectory=true"]
+        }),
+        new HappyPack({
+            threadPool: happyThreadPool,
+            id: 'eslint',
+            loaders: ["eslint-loader?{parser: 'babel-eslint'}"]
+        }),
+        new HappyPack({
+            threadPool: happyThreadPool,
+            id: 'ng-annotate-and-cached-babel-loader',
+            loaders: ['ng-annotate', 'babel-loader?cacheDirectory=true']
         })
     ],
     node: {
@@ -105,19 +128,20 @@ module.exports = {
         loaders: [
             {
                 test: /\.jsx$/,
-                loader: 'babel',
+                loader: 'happypack/loader?id=cached-babel',
                 exclude: /node_modules/,
                 include: __dirname,
             },
             {
                 test: /\.js$/,
-                loaders: ['ng-annotate', 'babel'],
+                loaders: ['happypack/loader?id=ng-annotate-and-cached-babel-loader'],
                 exclude: /node_modules/,
                 include: __dirname,
             },
             {
                 test: /\.js$/,
-                loader: "eslint-loader?{parser: 'babel-eslint'}",
+                loaders: ['happypack/loader?id=eslint'],
+                // loader: "eslint-loader?{parser: 'babel-eslint'}",
                 exclude: /node_modules|vendor/,
                 include: __dirname,
             },