Skip to content

Instantly share code, notes, and snippets.

@R45H
Created July 1, 2020 15:44
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 R45H/4ca7ee23ee021e483ae7e698068105a6 to your computer and use it in GitHub Desktop.
Save R45H/4ca7ee23ee021e483ae7e698068105a6 to your computer and use it in GitHub Desktop.
server
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpack = require('webpack')
const PRODUCTION = 'production'
const DEVELOPMENT = 'development'
const { NODE_ENV } = process.env
const IS_PROD = NODE_ENV === PRODUCTION
const plugins = [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, '../app/index.html'),
filename: 'index.html',
}),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
]
const entry = {
app: [path.resolve(__dirname, '../app/index.js')],
}
if (!IS_PROD) {
plugins.push(new webpack.HotModuleReplacementPlugin())
entry.app.unshift('webpack-hot-middleware/client?reload=true')
}
module.exports = {
mode: IS_PROD ? PRODUCTION : DEVELOPMENT,
entry,
devtool: IS_PROD ? false : 'source-map',
optimization: {
splitChunks: {
chunks: 'all',
},
runtimeChunk: {
name: 'runtime',
},
},
plugins,
devServer: {
contentBase: path.resolve(__dirname, '../dist'),
hot: true,
},
output: {
filename: '[name].[hash].js',
path: path.resolve(__dirname, '../dist'),
publicPath: '/',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
],
},
}
if (process.env.NODE_ENV === 'development') {
require('dotenv').config()
}
const { startHttpServer } = require('./app')
startHttpServer().catch((error) => {
console.error('Error while starting http server')
console.error(error)
process.exit(1)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment