This repository has been archived by the owner on May 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwebpack.server.config.js
53 lines (47 loc) · 1.99 KB
/
webpack.server.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* Copyright (c) 2021, 2022, Oracle and/or its affiliates.
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
*/
/*
* Creates "server-bundle.js" for the server containing the Server Code and the React App.
*/
const path = require('path');
const { merge } = require('webpack-merge');
const webpackNodeExternals = require('webpack-node-externals');
const webpack = require('webpack');
const baseConfig = require('./webpack.base.config.js');
const config = {
// inform WebPack that we are building a bundle for NodeJS rather
// than for the browser and to avoid packaging built-ins.
target: 'node',
// tell WebPack the root file of our server application
// usually the root file is "index.js" enabling just the server directory to be imported,
// but specifically naming it "server.js" makes it a lot clearer that this file will only
// run on the server.
entry: './src/server/server.js',
// tell WebPack the name of the generated output file and where to put it
output: {
filename: 'server-bundle.js',
path: path.resolve(__dirname, 'dist'),
},
// Tell WebPack to not bundle any libraries into our output bundle on the server
// if that library exists in the "node-modules" folder. This is because on the server
// Node can get the dependencies from node_modules on start up therefore they do not
// have to be in the bundle
// (unlike with the client bundle which has to have all the dependencies in it)
externals: [webpackNodeExternals(),
'react-helmet'],
devtool: 'source-map',
plugins: [
new webpack.DefinePlugin({
'process.env.IS_BROWSER': false,
'process.env.AUTH': JSON.stringify(process.env.AUTH),
'process.env.AUTH_PARAMS': JSON.stringify(process.env.AUTH_PARAMS),
}),
new webpack.SourceMapDevToolPlugin({
filename: '[name].js.map',
}),
],
};
// merge the base config and this config together to produce the full server config
module.exports = merge(baseConfig, config);