Last active
November 23, 2020 04:52
-
-
Save secf4ult/fe0d9f27ab54137e81ee72f9004c1eca to your computer and use it in GitHub Desktop.
webpack config template
This file contains 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 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