-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathwebpack.config.server.js
65 lines (59 loc) · 1.9 KB
/
webpack.config.server.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
const webpack = require('webpack')
const webpackNodeExternals = require('webpack-node-externals')
const path = require('path')
const {config, when, cleanList} = require('./shared/index.js')
const {cacheDirectory} = require('./shared/config.js')
const createCompilerRules = require('./shared/module-rules-compiler.js')
const manifestLoaderRules = require('./shared/module-rules-manifest-loader.js')
const {aliasFromConfig} = require('./shared/resolve-alias.js')
const {resolveLoader} = require('./shared/resolve-loader.js')
const filename = '[name].[chunkhash:8].js'
/** @typedef {import('webpack').Configuration} WebpackConfig */
const isProduction = process.env.NODE_ENV === 'production'
/** @type {WebpackConfig} */
const webpackConfig = {
name: 'server',
context: path.resolve(process.cwd(), 'src'),
mode: isProduction ? 'production' : 'development',
resolve: {
alias: {...aliasFromConfig},
extensions: ['.js', '.json', '.ts', '.tsx'],
modules: ['node_modules', path.resolve(process.cwd())]
},
entry: './server.js',
target: 'node',
output: {
chunkFilename: filename,
filename,
path: path.resolve(process.cwd(), 'build'),
pathinfo: false
},
optimization: {
checkWasmTypes: false,
minimize: true,
nodeEnv: false
},
cache: {
type: 'filesystem',
cacheDirectory,
compression: !isProduction ? 'gzip' : false
},
externals: [webpackNodeExternals()],
plugins: [new webpack.DefinePlugin({'global.GENTLY': false})],
resolveLoader,
module: {
rules: cleanList([
createCompilerRules({isServer: true}),
{
// ignore css/scss/svg require/imports files in the server
test: /(\.svg|\.s?css)$/,
type: 'asset/inline',
generator: {
dataUrl: () => ''
}
},
when(config['externals-manifest'], () => manifestLoaderRules(config['externals-manifest']))
])
}
}
module.exports = webpackConfig