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

Optimize embed size. #20

Merged
merged 1 commit into from
Mar 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions 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 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
50 changes: 27 additions & 23 deletions 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 All @@ -45,9 +46,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 @@ -162,23 +164,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 @@ -244,16 +253,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 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