-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.webpack.config.js
More file actions
155 lines (132 loc) · 4.38 KB
/
server.webpack.config.js
File metadata and controls
155 lines (132 loc) · 4.38 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
const path = require("path");
const webpack = require("webpack");
const nodeExternals = require("webpack-node-externals");
const ModuleNotFoundPlugin = require("react-dev-utils/ModuleNotFoundPlugin");
const CaseSensitivePathsPlugin = require("case-sensitive-paths-webpack-plugin");
const typescriptFormatter = require("react-dev-utils/typescriptFormatter");
module.exports.createServerWebpackConfig = function createServerWebpackConfig({
mode = "development",
entry = "./index.ts",
isDebug = true
} = {}) {
entry = path.resolve(entry);
const context = path.dirname(entry);
const serverConfig = {
context,
mode,
name: "server",
target: "node",
entry: {
index: [require.resolve("./server-hmr"), entry]
},
output: {
publicPath: "/",
pathinfo: isDebug,
path: path.resolve("build"),
filename: "[name].js",
chunkFilename: "chunks/[name].js",
libraryTarget: "umd",
libraryExport: "default",
globalObject: "(typeof self !== 'undefined' ? self : this)",
hotUpdateMainFilename: "updates/[hash].hot-update.json",
hotUpdateChunkFilename: "updates/[id].[hash].hot-update.js",
// Point sourcemap entries to original disk location (format as URL on Windows)
devtoolModuleFilenameTemplate: info =>
path.resolve(info.absoluteResourcePath).replace(/\\/g, "/")
},
// Webpack mutates resolve object, so clone it to avoid issues
// https://github.com/webpack/webpack/issues/4817
resolve: {
modules: ["node_modules", context],
extensions: [".wasm", ".mjs", ".js", ".json", ".ts", ".tsx"],
// Whether to resolve symlinks to their symlinked location.
symlinks: false
},
module: {
rules: [
// Rules for TS / TSX
{
test: /\.(ts|tsx)$/,
exclude: /(node_modules)/,
use: [
{
loader: "thread-loader",
options: {
workers: require("os").cpus().length - 1
}
},
{
loader: "ts-loader",
options: {
// This implicitly sets `transpileOnly` to `true`
happyPackMode: true,
compilerOptions: {
// force es modules for tree shaking
module: "esnext",
// use same module resolution
moduleResolution: "node",
// allow using Promises, Array.prototype.includes, String.prototype.padStart, etc.
lib: ["es2017"],
// use async/await instead of embedding polyfills
target: "es2017"
}
}
}
]
}
]
},
resolveLoader: {
modules: [path.join(__dirname, "./node_modules"), "node_modules"]
},
externals: [nodeExternals()],
plugins: [
// This gives some necessary context to module not found errors, such as
// the requesting resource
new ModuleNotFoundPlugin(process.cwd()),
// https://github.com/Urthen/case-sensitive-paths-webpack-plugin
new CaseSensitivePathsPlugin(),
// https://webpack.js.org/plugins/banner-plugin/
new webpack.BannerPlugin({
// https://github.com/evanw/node-source-map-support
banner: `require("${require.resolve(
"source-map-support"
)}").install();`,
raw: true,
entryOnly: false
}),
new webpack.HotModuleReplacementPlugin(),
new (require("fork-ts-checker-webpack-plugin"))({
// https://github.com/facebook/create-react-app/pull/5607
compilerOptions: {
module: "esnext",
moduleResolution: "node",
resolveJsonModule: true,
noEmit: true
},
async: false,
silent: true,
checkSyntacticErrors: true,
formatter: typescriptFormatter
})
],
stats: "none",
// https://webpack.js.org/configuration/optimization
optimization: {
// Do not modify/set the value of `process.env.NODE_ENV`
nodeEnv: false
},
// Do not replace node globals with polyfills
// https://webpack.js.org/configuration/node/
node: {
console: false,
global: false,
process: false,
Buffer: false,
__filename: false,
__dirname: false
},
devtool: "cheap-module-inline-source-map"
};
return serverConfig;
};