cache webpack resources and run loaders in concurrent mode

This commit is contained in:
vparomskiy 2019-01-31 16:09:50 +02:00
parent 094ef761cd
commit e9e10d74b8
3 changed files with 60 additions and 9 deletions

View File

@ -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": {

View File

@ -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,
},

View File

@ -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,
},