Created
January 4, 2019 23:22
-
-
Save arashkevich25/56f9629a37aaf02a175385e11ffb7adc to your computer and use it in GitHub Desktop.
SSR react application webpack config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
const autoprefixer = require('autoprefixer'); | |
const browserConfig = { | |
entry: './browser/index.js', | |
output: { | |
path: __dirname, | |
publicPath: '/', | |
filename: './public/bundle.js' | |
}, | |
devtool: 'cheap-module-source-map', | |
module: { | |
rules: [ | |
{ | |
test: [/\.svg$/, /\.gif$/, /\.jpe?g$/, /\.png$/], | |
loader: 'file-loader', | |
options: { | |
name: 'public/media/[name].[ext]', | |
publicPath: url => url.replace(/public/, '') | |
} | |
}, | |
{ | |
test: /\.css$/, | |
use: ExtractTextPlugin.extract({ | |
use: [ | |
{ | |
loader: 'css-loader', | |
options: { importLoaders: 1 } | |
}, | |
{ | |
loader: 'postcss-loader', | |
options: { plugins: [autoprefixer()] } | |
} | |
] | |
}) | |
}, | |
{ | |
test: /js$/, | |
exclude: /(node_modules)/, | |
loader: 'babel-loader' | |
} | |
] | |
}, | |
plugins: [ | |
new ExtractTextPlugin({ | |
filename: './public/css/[name].css' | |
}) | |
] | |
}; | |
const serverConfig = { | |
entry: './server/index.js', | |
target: 'node', | |
output: { | |
path: __dirname, | |
filename: 'server.js', | |
libraryTarget: 'commonjs2' | |
}, | |
devtool: 'cheap-module-source-map', | |
module: { | |
rules: [ | |
{ | |
test: [/\.svg$/, /\.gif$/, /\.jpe?g$/, /\.png$/], | |
loader: 'file-loader', | |
options: { | |
name: '../public/media/[name].[ext]', | |
publicPath: url => url.replace(/public/, ''), | |
emit: false | |
} | |
}, | |
{ | |
test: /\.css$/, | |
use: [ | |
{ | |
loader: 'css-loader/locals' | |
} | |
] | |
}, | |
{ | |
test: /js$/, | |
exclude: /(node_modules)/, | |
loader: 'babel-loader' | |
} | |
] | |
} | |
}; | |
module.exports = [browserConfig, serverConfig]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment