This repository has been archived by the owner on Sep 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
93 lines (90 loc) · 1.75 KB
/
webpack.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
const webpack = require('webpack')
const { html, getVersion } = require('./scripts/html')
const gitHubUrl = require('./package.json').homepage
const VERSION = getVersion()
const cfg = {
entry: {
main: './src/index.tsx',
chatbutton: './src/chatbutton.ts',
demo: './src/demo.tsx',
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
},
module: {
rules: [
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader',
},
],
},
{
test: /\.svg$/,
use: ['@svgr/webpack'],
},
],
},
externals: {
react: 'React',
'react-dom': 'ReactDOM',
'twilio-chat': ['Twilio', 'Chat'],
twemoji: 'twemoji',
},
}
module.exports = [
{
...cfg,
mode: 'production',
name: 'production',
plugins: [
new webpack.DefinePlugin({
GLOBAL_IS_PRODUCTION: JSON.stringify(true),
GLOBAL_VERSION: JSON.stringify(VERSION),
GLOBAL_GITHUB_URL: JSON.stringify(gitHubUrl),
}),
],
},
{
...cfg,
name: 'development',
mode: 'development',
devtool: 'source-map',
devServer: {
contentBase: './web',
before: (app, server, compiler) => {
app.get('/', (req, res) => {
res.set('Content-Type', 'text/html')
res.send(
html({
GRAPHQL_API_ENDPOINT: process.env.GRAPHQL_API_ENDPOINT,
GRAPHQL_API_KEY: process.env.GRAPHQL_API_KEY,
VERSION,
IS_PRODUCTION: JSON.stringify(false),
}),
)
})
},
},
module: {
rules: [
...cfg.module.rules,
{
enforce: 'pre',
test: /\.js$/,
loader: 'source-map-loader',
},
],
},
plugins: [
new webpack.DefinePlugin({
GLOBAL_IS_PRODUCTION: JSON.stringify(false),
GLOBAL_VERSION: JSON.stringify(VERSION),
GLOBAL_GITHUB_URL: JSON.stringify(gitHubUrl),
}),
],
},
]