Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arashkevich25/56f9629a37aaf02a175385e11ffb7adc to your computer and use it in GitHub Desktop.
Save arashkevich25/56f9629a37aaf02a175385e11ffb7adc to your computer and use it in GitHub Desktop.
SSR react application webpack config
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