Webpack Reuse proxies

This commit is contained in:
Nicolas Gotchac 2016-11-24 03:20:12 +01:00
parent 0750d82115
commit 259b91da50
3 changed files with 48 additions and 46 deletions

View File

@ -56,23 +56,21 @@ module.exports = {
debug: !isProd, debug: !isProd,
cache: !isProd, cache: !isProd,
devtool: isProd ? '#eval' : '#cheap-module-eval-source-map', devtool: isProd ? '#eval' : '#cheap-module-eval-source-map',
context: path.join(__dirname, '../src'), context: path.join(__dirname, '../src'),
entry: entry, entry: entry,
output: { output: {
path: path.join(__dirname, '../', DEST), path: path.join(__dirname, '../', DEST),
filename: '[name].[hash].js' filename: '[name].[hash].js'
}, },
module: { module: {
loaders: [ loaders: [
{ {
test: /\.js$/, test: /\.js$/,
exclude: [ /node_modules/, /vendor\.js$/ ], exclude: /node_modules/,
loaders: [ 'happypack/loader?id=js' ] loaders: [ 'happypack/loader?id=js' ]
}, },
{
test: /vendor\.js$/,
loaders: [ 'file?name=[name].[hash].[ext]' ]
},
{ {
test: /\.js$/, test: /\.js$/,
include: /node_modules\/material-ui-chip-input/, include: /node_modules\/material-ui-chip-input/,
@ -110,6 +108,7 @@ module.exports = {
/node_modules\/sinon/ /node_modules\/sinon/
] ]
}, },
resolve: { resolve: {
root: path.join(__dirname, '../node_modules'), root: path.join(__dirname, '../node_modules'),
fallback: path.join(__dirname, '../node_modules'), fallback: path.join(__dirname, '../node_modules'),
@ -140,6 +139,7 @@ module.exports = {
autoprefixer: true autoprefixer: true
}) })
], ],
plugins: (function () { plugins: (function () {
const plugins = Shared.getPlugins().concat([ const plugins = Shared.getPlugins().concat([
new CopyWebpackPlugin([{ from: './error_pages.css', to: 'styles.css' }], {}), new CopyWebpackPlugin([{ from: './error_pages.css', to: 'styles.css' }], {}),
@ -171,7 +171,7 @@ module.exports = {
if (!isProd) { if (!isProd) {
plugins.push( plugins.push(
new webpack.optimize.CommonsChunkPlugin({ new webpack.optimize.CommonsChunkPlugin({
filename: 'commons.js', filename: 'commons.[hash].js',
name: 'commons' name: 'commons'
}) })
); );
@ -179,47 +179,12 @@ module.exports = {
return plugins; return plugins;
}()), }()),
devServer: { devServer: {
contentBase: path.resolve(__dirname, `../${DEST}`), contentBase: path.resolve(__dirname, `../${DEST}`),
historyApiFallback: false, historyApiFallback: false,
quiet: false, quiet: false,
hot: !isProd, hot: !isProd,
proxy: [ proxy: Shared.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
}
]
} }
}; };

View File

@ -68,6 +68,45 @@ function getPlugins (_isProd = isProd) {
return plugins; 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 = { module.exports = {
getPlugins: getPlugins getPlugins: getPlugins,
proxies: proxies
}; };

View File

@ -29,7 +29,6 @@ let modules = [
'brace', 'brace',
'browserify-aes', 'browserify-aes',
'chart.js', 'chart.js',
'ethereumjs-tx',
'lodash', 'lodash',
'material-ui', 'material-ui',
'mobx', 'mobx',
@ -58,7 +57,6 @@ module.exports = {
}, },
{ {
test: /\.js$/, test: /\.js$/,
include: /(ethereumjs-tx)/,
loaders: [ 'happypack/loader?id=js' ] loaders: [ 'happypack/loader?id=js' ]
} }
] ]