Skip to content

Instantly share code, notes, and snippets.

@sibelius
Created July 14, 2020 14:59
Show Gist options
  • Save sibelius/0053920f37f38f8982f0b44f5852cc6d to your computer and use it in GitHub Desktop.
Save sibelius/0053920f37f38f8982f0b44f5852cc6d to your computer and use it in GitHub Desktop.
Webpack config for server
const path = require('path');
const webpack = require('webpack');
const WebpackNodeExternals = require('webpack-node-externals');
const ReloadServerPlugin = require('reload-server-webpack-plugin');
const cwd = process.cwd();
module.exports = {
mode: 'development',
devtool: 'cheap-eval-source-map',
entry: {
server: [
// 'webpack/hot/poll?1000',
'./src/index.ts',
],
},
output: {
path: path.resolve('build'),
filename: 'api.js',
// https://github.com/webpack/webpack/pull/8642
futureEmitAssets: true,
},
watch: true,
target: 'node',
externals: [
WebpackNodeExternals({
whitelist: ['webpack/hot/poll?1000'],
}),
WebpackNodeExternals({
modulesDir: path.resolve(__dirname, '../../node_modules'),
whitelist: [/@app/],
}),
],
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json', '.mjs'],
},
module: {
rules: [
{
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto',
},
{
test: /\.(js|jsx|ts|tsx)?$/,
use: {
loader: 'babel-loader?cacheDirectory',
},
exclude: [/node_modules/],
include: [path.join(cwd, 'src'), path.join(cwd, '../')],
},
],
},
plugins: [
new ReloadServerPlugin({
script: path.resolve('build', 'api.js'),
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
}),
],
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment