Created
July 1, 2020 15:44
-
-
Save R45H/4ca7ee23ee021e483ae7e698068105a6 to your computer and use it in GitHub Desktop.
server
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 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', | |
}, | |
}, | |
], | |
}, | |
} |
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
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