Skip to content

Instantly share code, notes, and snippets.

@secf4ult
Last active November 23, 2020 04:52
Show Gist options
  • Save secf4ult/fe0d9f27ab54137e81ee72f9004c1eca to your computer and use it in GitHub Desktop.
Save secf4ult/fe0d9f27ab54137e81ee72f9004c1eca to your computer and use it in GitHub Desktop.
webpack config template
const config = {
entry: {
main: __dirname + '/app/main.js'
},
output: {
path: __dirname + '/public',
filename: 'bundle.js'
},
module: {
rules: [
{
test: /(\.jsx|\.js)$/,
use: {
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env', '@babel/preset-react'
]
}
},
exclude: /node_modules/
},
{
test: /\.css$/,
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader',
options: {
modules: {
localIdentName: '[name]__[local]--[hash:base64:5]'
}
}
},
{
loader: 'postcss-loader'
}
]
}
]
},
plugins: [
],
}
const developmentConfig = {
...config,
mode: 'development',
devtool: 'eval-source-map',
devServer: {
contentBase: './public',
historyApiFallback: true,
inline: true
}
}
const productionConfig = {
...config,
mode: 'production',
devtool: 'null',
devServer: {
contentBase: './public',
historyApiFallback: true,
inline: true
}
}
const serverConfig = {
...config,
target: 'node'
}
module.exports = [ process.env === 'PRODUCTION' ? productionConfig : developmentConfig,
serverConfig ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment