Skip to content

Commit

Permalink
feat(build): parallelize build process
Browse files Browse the repository at this point in the history
* re-add happypack back into build process to parallelize where
possibile.  at this time typescript files are not able to be built in
parallel.
* removed erroneously committed file (from 2015).
  • Loading branch information
icfantv committed Mar 8, 2017
1 parent 1a8d137 commit 686a0b1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 41 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -19,6 +19,7 @@ test/google/node_modules/
# Build Files
.awcache/
.gradle/
.happypack/
build/
dist/
transpiled/
Expand Down
14 changes: 0 additions & 14 deletions app/scripts/modules/core/pipeline/config/dist/index.html

This file was deleted.

5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -15,7 +15,7 @@
"npm": "3.10.8"
},
"scripts": {
"clean": "rimraf .awcache build coverage node_modules transpiled",
"clean": "rimraf .awcache .happypack build coverage node_modules transpiled",
"build": "webpack --bail",
"eslint": "eslint -c .eslintrc app/scripts/modules",
"start": "sh ./start.sh",
Expand Down Expand Up @@ -84,7 +84,7 @@
"angular-mocks": "1.5.8",
"angulartics": "^1.1.2",
"angulartics-google-analytics": "^0.2.0",
"awesome-typescript-loader": "3.0.8",
"awesome-typescript-loader": "^3.1.2",
"babel-core": "^6.21.1",
"babel-loader": "^6.2.10",
"babel-preset-es2015": "^6.18.0",
Expand All @@ -97,6 +97,7 @@
"exports-loader": "^0.6.3",
"expose-loader": "^0.7.1",
"file-loader": "^0.10.0",
"happypack": "^3.0.3",
"html-loader": "0.4.0",
"html-webpack-plugin": "^2.28.0",
"imports-loader": "^0.7.0",
Expand Down
71 changes: 46 additions & 25 deletions webpack.common.js
@@ -1,12 +1,16 @@
const webpack = require('webpack');
const HappyPack = require('happypack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const {CheckerPlugin} = require('awesome-typescript-loader');
const webpack = require('webpack');

const path = require('path');
const NODE_MODULE_PATH = path.join(__dirname, 'node_modules');
const fs = require('fs');

function configure(IS_TEST) {

const POOL_SIZE = IS_TEST ? 3 : 6;
const happyThreadPool = HappyPack.ThreadPool({size: POOL_SIZE});

const config = {
plugins: [],
output: IS_TEST ? undefined : {
Expand All @@ -33,17 +37,7 @@ function configure(IS_TEST) {
{test: /\.json$/, loader: 'json-loader'},
{test: /\.ts$/, use: 'awesome-typescript-loader', exclude: /node_modules/},
{test: /\.(woff|otf|ttf|eot|svg|png|gif|ico)(.*)?$/, use: 'file-loader'},
{
test: /\.js$/,
exclude: /node_modules(?!\/clipboard)/,
use: [
'ng-annotate-loader',
'angular-loader',
'babel-loader',
'envify-loader',
'eslint-loader'
]
},
{test: /\.js$/, use: ['happypack/loader?id=js'], exclude: /node_modules(?!\/clipboard)/},
{
test: require.resolve('jquery'),
use: [
Expand All @@ -53,11 +47,7 @@ function configure(IS_TEST) {
},
{
test: /\.less$/,
use: [
'style-loader',
'css-loader',
'less-loader'
]
use: IS_TEST ? ['style-loader', 'css-loader', 'less-loader'] : ['happypack/loader?id=less']
},
{
test: /\.css$/,
Expand All @@ -68,10 +58,7 @@ function configure(IS_TEST) {
},
{
test: /\.html$/,
use: [
'ngtemplate-loader?relativeTo=' + (path.resolve(__dirname)) + '/',
'html-loader'
]
use: ['happypack/loader?id=html']
}
],
},
Expand All @@ -91,6 +78,31 @@ function configure(IS_TEST) {
}
}

config.plugins = [
new HappyPack({
id: 'html',
loaders: [
'ngtemplate-loader?relativeTo=' + (path.resolve(__dirname)) + '/',
'html-loader'
],
threadPool: happyThreadPool
}),
new HappyPack({
id: 'js',
loaders: [
'ng-annotate-loader',
'angular-loader',
'babel-loader',
'envify-loader',
'eslint-loader'
],
threadPool: happyThreadPool,
cacheContext: {
env: process.env
}
})
];

if (!IS_TEST) {
config.entry = {
settings: './settings.js',
Expand All @@ -104,7 +116,16 @@ function configure(IS_TEST) {
]
};

config.plugins = [
config.plugins.push(...[
new HappyPack({
id: 'less',
loaders: [
'style-loader',
'css-loader',
'less-loader'
],
threadPool: happyThreadPool
}),
new webpack.ContextReplacementPlugin(/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/, __dirname),
new webpack.optimize.CommonsChunkPlugin({name: 'vendor', filename: 'vendor.bundle.js'}),
new webpack.optimize.CommonsChunkPlugin('init'),
Expand All @@ -123,13 +144,13 @@ function configure(IS_TEST) {
return chunks.indexOf(a.names[0]) - chunks.indexOf(b.names[0]);
}
})
];
]);
}

// this is temporary and will be deprecated in WP3. moving forward,
// loaders will individually need to accept this as an option.
config.plugins.push(new webpack.LoaderOptionsPlugin({debug: !IS_TEST}));
config.plugins.push(new CheckerPlugin());
// config.plugins.push(new CheckerPlugin());

return config;
}
Expand Down

0 comments on commit 686a0b1

Please sign in to comment.