Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
[stable] Optimize JS build (#8093)
Browse files Browse the repository at this point in the history
* Extract common chunks plugin.

* Fix common CSS.

* Fix js push for stable.

* Remove arguments to getPlugins.
  • Loading branch information
tomusdrw authored Mar 13, 2018
1 parent a9a58d2 commit a6d732e
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 45 deletions.
195 changes: 178 additions & 17 deletions js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
"Parity"
],
"scripts": {
"build": "npm run build:inject && npm run build:app && npm run build:embed",
"build": "npm run build:inject && npm run build:app:embed",
"build:app": "webpack --config webpack/app",
"build:inject": "webpack --config webpack/inject",
"build:embed": "cross-env EMBED=1 node webpack/embed",
"build:app:embed": "cross-env EMBED=1 node webpack/embed",
"build:i18n": "npm run clean && npm run build && babel-node ./scripts/build-i18n.js",
"ci:build": "cross-env NODE_ENV=production npm run build",
"clean": "rimraf ./.build ./.coverage ./.happypack",
Expand Down
2 changes: 1 addition & 1 deletion js/scripts/push-cargo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e
# variables
PVER="1-9"
UTCDATE=`date -u "+%Y%m%d-%H%M%S"`
BRANCH="beta"
BRANCH="stable"
GIT_PARITY="https://${GITHUB_JS_PRECOMPILED}:@github.com/paritytech/parity.git"

echo "*** [cargo] Setting up GitHub config for parity"
Expand Down
50 changes: 27 additions & 23 deletions js/webpack/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const fs = require('fs');
const path = require('path');
const rimraf = require('rimraf');
const flatten = require('lodash.flatten');
const webpack = require('webpack');
// const ReactIntlAggregatePlugin = require('react-intl-aggregate-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const WebpackErrorNotificationPlugin = require('webpack-error-notification');
Expand Down Expand Up @@ -47,9 +48,10 @@ const EMBED = process.env.EMBED;
const isProd = ENV === 'production';
const isEmbed = EMBED === '1' || EMBED === 'true';

const entry = isEmbed
? { embed: ['babel-polyfill', './embed.js'] }
: { bundle: ['babel-polyfill', './index.parity.js'] };
const entry = {
embed: ['babel-polyfill', './embed.js'],
bundle: ['babel-polyfill', './index.parity.js']
};

module.exports = {
cache: !isProd,
Expand Down Expand Up @@ -164,23 +166,30 @@ module.exports = {
},

plugins: (function () {
let plugins = Shared.getPlugins().concat(
new WebpackErrorNotificationPlugin(),
new ExtractTextPlugin({
filename: `${isEmbed ? 'embed' : 'bundle'}.css`
}),
);

if (!isEmbed) {
plugins = [].concat(
plugins,
let plugins = []
.concat(Shared.getPlugins())
.concat(
new WebpackErrorNotificationPlugin(),
new ExtractTextPlugin({
filename: '[name].css',
allChunks: true
})
)
.concat(
new HtmlWebpackPlugin({
title: 'Parity Bar',
filename: 'embed.html',
template: './index.parity.ejs',
favicon: FAVICON,
chunks: ['commons', 'embed']
}),

new HtmlWebpackPlugin({
title: 'Parity',
filename: 'index.html',
template: './index.parity.ejs',
favicon: FAVICON,
chunks: ['bundle']
chunks: ['commons', 'bundle']
}),

new CopyWebpackPlugin(
Expand Down Expand Up @@ -246,16 +255,11 @@ module.exports = {
{}
)
);
}

if (isEmbed) {
plugins.push(
new HtmlWebpackPlugin({
title: 'Parity Bar',
filename: 'embed.html',
template: './index.parity.ejs',
favicon: FAVICON,
chunks: ['embed']
if (isProd) {
plugins.unshift(
new webpack.optimize.CommonsChunkPlugin({
name: 'commons'
})
);
}
Expand Down
2 changes: 0 additions & 2 deletions js/webpack/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const webpack = require('webpack');
const HappyPack = require('happypack');
const PackageJson = require('../package.json');

const EMBED = process.env.EMBED;
const ENV = process.env.NODE_ENV || 'development';
const isProd = ENV === 'production';
const UI_VERSION = PackageJson
Expand All @@ -38,7 +37,6 @@ function getPlugins (_isProd = isProd) {
const plugins = [
new webpack.DefinePlugin({
'process.env': {
EMBED: JSON.stringify(EMBED),
NODE_ENV: JSON.stringify(ENV),
RPC_ADDRESS: JSON.stringify(process.env.RPC_ADDRESS),
PARITY_URL: JSON.stringify(process.env.PARITY_URL),
Expand Down

0 comments on commit a6d732e

Please sign in to comment.