From 259b91da506c051508730cb0d5de68a4c8ac0b41 Mon Sep 17 00:00:00 2001 From: Nicolas Gotchac Date: Thu, 24 Nov 2016 03:20:12 +0100 Subject: [PATCH] Webpack Reuse proxies --- js/webpack/config.js | 51 +++++++------------------------------------- js/webpack/shared.js | 41 ++++++++++++++++++++++++++++++++++- js/webpack/vendor.js | 2 -- 3 files changed, 48 insertions(+), 46 deletions(-) diff --git a/js/webpack/config.js b/js/webpack/config.js index 36f022297..a99984f27 100644 --- a/js/webpack/config.js +++ b/js/webpack/config.js @@ -56,23 +56,21 @@ module.exports = { debug: !isProd, cache: !isProd, devtool: isProd ? '#eval' : '#cheap-module-eval-source-map', + context: path.join(__dirname, '../src'), entry: entry, output: { path: path.join(__dirname, '../', DEST), filename: '[name].[hash].js' }, + module: { loaders: [ { test: /\.js$/, - exclude: [ /node_modules/, /vendor\.js$/ ], + exclude: /node_modules/, loaders: [ 'happypack/loader?id=js' ] }, - { - test: /vendor\.js$/, - loaders: [ 'file?name=[name].[hash].[ext]' ] - }, { test: /\.js$/, include: /node_modules\/material-ui-chip-input/, @@ -110,6 +108,7 @@ module.exports = { /node_modules\/sinon/ ] }, + resolve: { root: path.join(__dirname, '../node_modules'), fallback: path.join(__dirname, '../node_modules'), @@ -140,6 +139,7 @@ module.exports = { autoprefixer: true }) ], + plugins: (function () { const plugins = Shared.getPlugins().concat([ new CopyWebpackPlugin([{ from: './error_pages.css', to: 'styles.css' }], {}), @@ -171,7 +171,7 @@ module.exports = { if (!isProd) { plugins.push( new webpack.optimize.CommonsChunkPlugin({ - filename: 'commons.js', + filename: 'commons.[hash].js', name: 'commons' }) ); @@ -179,47 +179,12 @@ module.exports = { return plugins; }()), + devServer: { contentBase: path.resolve(__dirname, `../${DEST}`), historyApiFallback: false, quiet: false, hot: !isProd, - proxy: [ - { - context: (pathname, req) => { - return pathname === '/' && req.method === 'HEAD'; - }, - target: 'http://127.0.0.1:8180', - changeOrigin: true, - autoRewrite: true - }, - { - context: '/api', - target: 'http://127.0.0.1:8080', - changeOrigin: true, - autoRewrite: true - }, - { - context: '/app', - target: 'http://127.0.0.1:8080', - changeOrigin: true, - pathRewrite: { - '^/app': '' - } - }, - { - context: '/parity-utils', - target: 'http://127.0.0.1:3000', - changeOrigin: true, - pathRewrite: { - '^/parity-utils': '' - } - }, - { - context: '/rpc', - target: 'http://127.0.0.1:8080', - changeOrigin: true - } - ] + proxy: Shared.proxies } }; diff --git a/js/webpack/shared.js b/js/webpack/shared.js index 24b780e25..cc2553da2 100644 --- a/js/webpack/shared.js +++ b/js/webpack/shared.js @@ -68,6 +68,45 @@ function getPlugins (_isProd = isProd) { return plugins; } +const proxies = [ + { + context: (pathname, req) => { + return pathname === '/' && req.method === 'HEAD'; + }, + target: 'http://127.0.0.1:8180', + changeOrigin: true, + autoRewrite: true + }, + { + context: '/api', + target: 'http://127.0.0.1:8080', + changeOrigin: true, + autoRewrite: true + }, + { + context: '/app', + target: 'http://127.0.0.1:8080', + changeOrigin: true, + pathRewrite: { + '^/app': '' + } + }, + { + context: '/parity-utils', + target: 'http://127.0.0.1:3000', + changeOrigin: true, + pathRewrite: { + '^/parity-utils': '' + } + }, + { + context: '/rpc', + target: 'http://127.0.0.1:8080', + changeOrigin: true + } +]; + module.exports = { - getPlugins: getPlugins + getPlugins: getPlugins, + proxies: proxies }; diff --git a/js/webpack/vendor.js b/js/webpack/vendor.js index 8dfffea07..2e7edc771 100644 --- a/js/webpack/vendor.js +++ b/js/webpack/vendor.js @@ -29,7 +29,6 @@ let modules = [ 'brace', 'browserify-aes', 'chart.js', - 'ethereumjs-tx', 'lodash', 'material-ui', 'mobx', @@ -58,7 +57,6 @@ module.exports = { }, { test: /\.js$/, - include: /(ethereumjs-tx)/, loaders: [ 'happypack/loader?id=js' ] } ]