-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.server.config.js
executable file
·121 lines (112 loc) · 3.67 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const fs = require('fs');
const path = require('path');
const webpack = require('webpack'); // eslint-disable-line import/no-extraneous-dependencies
const { merge } = require('webpack-merge'); // eslint-disable-line import/no-extraneous-dependencies
const nodeExternals = require('webpack-node-externals');
const ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');
const parts = require('../webpack.parts');
// For externals
const pkg = require('./package.json');
const deps = require('../package.json').dependencies;
const PATHS = {
src: path.join(__dirname, 'src'),
clientServer: path.join(__dirname, 'src/server-client.tsx'),
build: path.join(__dirname, 'build'),
utils: path.join(__dirname, '../utilities'),
reactComponents: path.join(__dirname, '../therr-public-library/therr-react'),
public: '/',
};
const nodeModules = {};
fs.readdirSync('../node_modules').filter(x => ['.bin'].indexOf(x) === -1)
.forEach((mod) => { nodeModules[mod] = `commonjs ${mod}`; });
const common = merge([
{
entry: {
'server-client': path.join(PATHS.clientServer),
},
output: {
path: PATHS.build,
filename: 'server-client.js',
publicPath: PATHS.public,
libraryTarget: 'umd',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json', '.scss', '.css'],
alias: {
actions: path.join(__dirname, 'src/redux/actions/'),
enums: path.join(__dirname, 'src/constants/enums/'),
types: path.join(__dirname, 'src/redux/types/'),
'therr-react': path.join(__dirname, '../therr-public-library/therr-react/lib'),
'therr-styles': path.join(__dirname, '../therr-public-library/therr-styles/lib'),
'therr-js-utilities': path.join(__dirname, '../therr-public-library/therr-js-utilities/lib'),
},
fallback: {
fs: false,
tls: false,
net: false,
os: false,
path: false,
zlib: false,
http: require.resolve('http-browserify'),
https: require.resolve('https-browserify'),
stream: false,
crypto: false,
},
},
plugins: [
new ModuleFederationPlugin({
shared: {
axios: {
eager: true,
requiredVersion: deps.axios,
singleton: true,
},
},
}),
],
externals: [
...Object.keys(pkg.peerDependencies || {}),
nodeModules,
],
target: 'node',
node: {
__dirname: true,
__filename: true,
},
optimization: {
emitOnErrors: true,
moduleIds: 'deterministic',
},
},
parts.clean(),
parts.loadSvg(),
parts.processTypescript([PATHS.src], false),
parts.generateSourcemaps('source-map'),
parts.deDupe(),
]);
const buildDev = () => merge([
common,
{
mode: 'development',
externals: [
...Object.keys(pkg.peerDependencies || {}),
nodeExternals(),
],
},
parts.minifyJavaScript({ useSourceMap: false }),
]);
const buildProd = () => merge([
common,
{
mode: 'production',
},
// parts.analyzeBundle(),
parts.minifyJavaScript({ useSourceMap: true }),
]);
module.exports = (env) => {
process.env.BABEL_ENV = env;
if (env.production) {
return [buildProd()];
}
return [buildDev()];
};