From c8809b3396ff3295ccd3e1934277a62c686fc9e8 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 26 Oct 2016 13:44:38 +0200 Subject: [PATCH] Add inject to "bundle everything" list (#2871) * Add inject to "bundle everything" list * Fixes the `build-server` script // Updates Webpack config (#2872) * New Webpack config file for libraries * Added `parity-utils` path * Removed parity in CommonChunks prod --- js/build-server.js | 25 +++++++++- js/package.json | 17 ++++--- js/src/dapps/basiccoin.html | 2 +- js/src/dapps/gavcoin.html | 2 +- js/src/dapps/githubhint.html | 2 +- js/src/dapps/registry.html | 2 +- js/src/dapps/signaturereg.html | 2 +- js/src/dapps/tokenreg.html | 2 +- js/src/dev.parity.html | 2 +- js/src/dev.web3.html | 2 +- js/src/environment/index.js | 8 ++- js/src/{inject.js => web3.js} | 0 js/webpack.config.js | 27 +++++------ js/webpack.libraries.js | 89 ++++++++++++++++++++++++++++++++++ 14 files changed, 151 insertions(+), 31 deletions(-) rename js/src/{inject.js => web3.js} (100%) create mode 100644 js/webpack.libraries.js diff --git a/js/build-server.js b/js/build-server.js index 797e89183..9153f5ed2 100644 --- a/js/build-server.js +++ b/js/build-server.js @@ -24,17 +24,38 @@ var express = require('express'); var proxy = require('http-proxy-middleware'); var app = express(); +var wsProxy = proxy('ws://127.0.0.1:8180', { changeOrigin: true }); -app.use(express.static('build')); +app.use(express.static('.build')); app.use('/api/*', proxy({ target: 'http://127.0.0.1:8080', changeOrigin: true })); +app.use('/app/*', proxy({ + target: 'http://127.0.0.1:8080', + changeOrigin: true, + pathRewrite: { + '^/app': '' + } +})); + +app.use('/parity-utils/*', proxy({ + target: 'http://127.0.0.1:3000', + changeOrigin: true, + pathRewrite: { + '^/parity-utils': '' + } +})); + app.use('/rpc/*', proxy({ target: 'http://127.0.0.1:8080', changeOrigin: true })); -app.listen(3000); +app.use(wsProxy); + +var server = app.listen(3000); + +server.on('upgrade', wsProxy.upgrade); diff --git a/js/package.json b/js/package.json index d84b21d25..8992c7fa6 100644 --- a/js/package.json +++ b/js/package.json @@ -23,17 +23,22 @@ "Promise" ], "scripts": { - "build": "npm run build:dll && npm run build:app", + "build": "npm run build:dll && npm run build:app && npm run build:lib", "build:app": "webpack --progress", - "build:dll": "webpack --config webpack.vendor.js --progress", - "ci:build": "npm run ci:build:dll && npm run ci:build:app", + "build:lib": "webpack --config webpack.libraries --progress", + "build:dll": "webpack --config webpack.vendor --progress", + + "ci:build": "npm run ci:build:dll && npm run ci:build:dll && npm run ci:build:app", "ci:build:app": "NODE_ENV=production webpack", - "ci:build:dll": "NODE_ENV=production webpack --config webpack.vendor.js", + "ci:build:lib": "NODE_ENV=production webpack --config webpack.libraries", + "ci:build:dll": "NODE_ENV=production webpack --config webpack.vendor", + + "start": "npm install && npm run build:dll && npm run start:app", + "start:app": "webpack-dev-server -d --history-api-fallback --open --hot --inline --progress --colors --port 3000", + "clean": "rm -rf ./build ./coverage", "coveralls": "npm run testCoverage && coveralls < coverage/lcov.info", "lint": "eslint --ignore-path .gitignore ./src/", - "start": "npm install && npm run build:dll && npm run start:app", - "start:app": "webpack-dev-server -d --history-api-fallback --open --hot --inline --progress --colors --port 3000", "test": "mocha 'src/**/*.spec.js'", "test:coverage": "istanbul cover _mocha -- 'src/**/*.spec.js'", "test:e2e": "mocha 'src/**/*.e2e.js'" diff --git a/js/src/dapps/basiccoin.html b/js/src/dapps/basiccoin.html index 9bcc368f3..7ac5cb3cb 100644 --- a/js/src/dapps/basiccoin.html +++ b/js/src/dapps/basiccoin.html @@ -10,7 +10,7 @@
- + diff --git a/js/src/dapps/gavcoin.html b/js/src/dapps/gavcoin.html index 928310a52..f777f2920 100644 --- a/js/src/dapps/gavcoin.html +++ b/js/src/dapps/gavcoin.html @@ -10,7 +10,7 @@
- + diff --git a/js/src/dapps/githubhint.html b/js/src/dapps/githubhint.html index 0084dd051..085b15953 100644 --- a/js/src/dapps/githubhint.html +++ b/js/src/dapps/githubhint.html @@ -10,7 +10,7 @@
- + diff --git a/js/src/dapps/registry.html b/js/src/dapps/registry.html index 21b09dc12..83c5e8c9b 100644 --- a/js/src/dapps/registry.html +++ b/js/src/dapps/registry.html @@ -10,7 +10,7 @@
- + diff --git a/js/src/dapps/signaturereg.html b/js/src/dapps/signaturereg.html index 3f74be28a..be62400d2 100644 --- a/js/src/dapps/signaturereg.html +++ b/js/src/dapps/signaturereg.html @@ -10,7 +10,7 @@
- + diff --git a/js/src/dapps/tokenreg.html b/js/src/dapps/tokenreg.html index ecb03d005..bcf04e298 100644 --- a/js/src/dapps/tokenreg.html +++ b/js/src/dapps/tokenreg.html @@ -10,7 +10,7 @@
- + diff --git a/js/src/dev.parity.html b/js/src/dev.parity.html index 20b8e965f..56811f7c2 100644 --- a/js/src/dev.parity.html +++ b/js/src/dev.parity.html @@ -7,6 +7,6 @@ dev::Parity.js - + diff --git a/js/src/dev.web3.html b/js/src/dev.web3.html index 97a47eb72..e55e0109b 100644 --- a/js/src/dev.web3.html +++ b/js/src/dev.web3.html @@ -7,6 +7,6 @@ dev::Web3 - + diff --git a/js/src/environment/index.js b/js/src/environment/index.js index 1dfda77aa..9b95bb0da 100644 --- a/js/src/environment/index.js +++ b/js/src/environment/index.js @@ -19,7 +19,13 @@ import './tests'; -const parityNode = process.env.NODE_ENV === 'production' ? 'http://127.0.0.1:8080' : ''; +const parityNode = ( + process.env.PARITY_URL && `http://${process.env.PARITY_URL}` + ) || ( + process.env.NODE_ENV === 'production' + ? 'http://127.0.0.1:8080' + : '' + ); export { parityNode diff --git a/js/src/inject.js b/js/src/web3.js similarity index 100% rename from js/src/inject.js rename to js/src/web3.js diff --git a/js/webpack.config.js b/js/webpack.config.js index 39415b1a1..c72ef8936 100644 --- a/js/webpack.config.js +++ b/js/webpack.config.js @@ -41,8 +41,9 @@ module.exports = { 'signaturereg': ['./dapps/signaturereg.js'], 'tokenreg': ['./dapps/tokenreg.js'], // library - 'inject': ['./inject.js'], 'parity': ['./parity.js'], + 'inject': ['./web3.js'], + 'web3': ['./web3.js'], // app 'index': ['./index.js'] }, @@ -136,10 +137,6 @@ module.exports = { 'babel?cacheDirectory=true' ] }), - new webpack.DllReferencePlugin({ - context: '.', - manifest: require(`./${DEST}/vendor-manifest.json`) - }), new CopyWebpackPlugin([{ from: './error_pages.css', to: 'styles.css' }], {}), new WebpackErrorNotificationPlugin(), new webpack.DefinePlugin({ @@ -149,6 +146,11 @@ module.exports = { PARITY_URL: JSON.stringify(process.env.PARITY_URL), LOGGING: JSON.stringify(!isProd) } + }), + + new webpack.DllReferencePlugin({ + context: '.', + manifest: require(`./${DEST}/vendor-manifest.json`) }) ]; @@ -164,16 +166,10 @@ module.exports = { if (isProd) { plugins.push( new webpack.optimize.CommonsChunkPlugin({ - chunks: [ 'index' ], + chunks: ['index'], name: 'commons' }) ); - plugins.push( - new webpack.optimize.CommonsChunkPlugin({ - chunks: [ 'parity' ], - name: 'parity' - }) - ); plugins.push(new webpack.optimize.OccurrenceOrderPlugin(false)); plugins.push(new webpack.optimize.DedupePlugin()); @@ -208,8 +204,11 @@ module.exports = { } }, '/parity-utils/*': { - target: 'http://127.0.0.1:8080', - changeOrigin: true + target: 'http://127.0.0.1:3000', + changeOrigin: true, + pathRewrite: { + '^/parity-utils': '' + } }, '/rpc/*': { target: 'http://localhost:8080', diff --git a/js/webpack.libraries.js b/js/webpack.libraries.js new file mode 100644 index 000000000..bf54a933f --- /dev/null +++ b/js/webpack.libraries.js @@ -0,0 +1,89 @@ +// Copyright 2015, 2016 Ethcore (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +// Run with `webpack --config webpack.libraries.js --progress` + +const HappyPack = require('happypack'); +const path = require('path'); +const webpack = require('webpack'); + +const ENV = process.env.NODE_ENV || 'development'; +const isProd = ENV === 'production'; +const DEST = process.env.BUILD_DEST || '.build'; + +module.exports = { + context: path.join(__dirname, './src'), + entry: { + // library + 'inject': ['./web3.js'], + 'web3': ['./web3.js'], + 'parity': ['./parity.js'] + }, + output: { + path: path.join(__dirname, DEST), + filename: '[name].js' + }, + module: { + loaders: [ + { + test: /\.js$/, + exclude: /node_modules/, + loader: 'happypack/loader?id=js' + }, + { + test: /\.json$/, + loaders: ['json'] + }, + { + test: /\.html$/, + loader: 'file?name=[name].[ext]' + } + ] + }, + plugins: (function () { + const plugins = [ + new HappyPack({ + id: 'js', + threads: 4, + loaders: [ 'babel' ] + }), + new webpack.DefinePlugin({ + 'process.env': { + NODE_ENV: JSON.stringify(ENV), + RPC_ADDRESS: JSON.stringify(process.env.RPC_ADDRESS), + PARITY_URL: JSON.stringify(process.env.PARITY_URL), + LOGGING: JSON.stringify(!isProd) + } + }) + ]; + + if (isProd) { + plugins.push(new webpack.optimize.OccurrenceOrderPlugin(false)); + plugins.push(new webpack.optimize.DedupePlugin()); + plugins.push(new webpack.optimize.UglifyJsPlugin({ + screwIe8: true, + compress: { + warnings: false + }, + output: { + comments: false + } + })); + } + + return plugins; + }()) +};