This repository was archived by the owner on Sep 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 195
/
Copy pathwebpack.config.js
227 lines (215 loc) · 6.04 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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
const path = require('path')
const webpack = require('webpack')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const GitRevisionPlugin = require('git-revision-webpack-plugin')
const gitRevisionPlugin = new GitRevisionPlugin()
let gitCommitHash = process.env.GIT_COMMIT_HASH || process.env.DEPLOY_TAG,
gitBranch = process.env.GIT_BRANCH
try {
gitCommitHash = gitRevisionPlugin.commithash()
gitBranch = gitRevisionPlugin.branch()
} catch (e) {
/* No Git repo found */
}
const isProduction = process.env.NODE_ENV === 'production'
const isTest = process.env.NODE_ENV === 'test'
const isStaging = process.env.NAMESPACE === 'staging'
const isDev = process.env.NAMESPACE === 'dev'
let TELEGRAM_BOT_USERNAME = 'origin_protocol_test_bot'
if (isStaging) {
TELEGRAM_BOT_USERNAME = 'originprotocol_verification_bot'
} else if (isProduction && !isDev) {
TELEGRAM_BOT_USERNAME = 'originprotocol_production_bot'
}
let devtool = 'cheap-module-source-map'
if (isTest || process.env.GENERATE_SOURCEMAP === 'false') {
devtool = false
} else if (isProduction) {
devtool = 'source-map'
}
const config = {
entry: {
app: './src/index.js'
},
devtool,
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'public')
},
externals: {
sequelize: 'sequelize', // Unused from event-cache
Web3: 'web3'
},
module: {
noParse: [/^react$/],
rules: [
{ test: /\.flow$/, loader: 'ignore-loader' },
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
plugins: [
[
'babel-plugin-fbt',
{
fbtEnumManifest: require('./translation/fbt/.enum_manifest.json')
}
],
'babel-plugin-fbt-runtime'
]
}
},
{
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto'
},
{
test: /\.css$/,
use: [
{
loader: isProduction ? MiniCssExtractPlugin.loader : 'style-loader'
},
{
loader: 'css-loader',
options: {
url: url => {
return url.match(/(svg|png)/) ? false : true
}
}
}
]
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: [
{
loader: isProduction ? 'file-loader' : 'url-loader',
options: isProduction ? { name: 'fonts/[name].[ext]' } : {}
}
]
}
]
},
resolve: {
extensions: ['.js', '.json'],
modules: [path.resolve(__dirname, 'src/constants'), './node_modules'],
symlinks: false
},
node: {
fs: 'empty'
},
devServer: {
port: 8081,
headers: {
'Access-Control-Allow-Origin': '*'
},
contentBase: path.join(__dirname, 'public')
},
watchOptions: {
poll: 2000
},
mode: isProduction ? 'production' : 'development',
plugins: [
new HtmlWebpackPlugin({
template: 'public/template.html',
inject: false,
network: process.env.NODE_ENV === 'test' ? 'test' : 'rinkeby',
metaMask: process.env.NODE_ENV === 'test' ? 'false' : 'true'
}),
new webpack.EnvironmentPlugin({
BUILD_TIMESTAMP: +new Date(),
DOCKER: false,
ENABLE_WECHAT_ATTESTATION: false,
ENABLE_CENTRALIZED_IDENTITY: false,
ENABLE_OKB: false,
ETH_NETWORK_ID: process.env.ETH_NETWORK_ID || null,
FACEBOOK_CLIENT_ID: null,
GAS_PRICE_KEY: null,
GIT_COMMIT_HASH: gitCommitHash,
GIT_BRANCH: gitBranch,
HOST: 'localhost',
LINKER_HOST: 'localhost',
GOOGLE_MAPS_API_KEY: process.env.GOOGLE_MAPS_API_KEY || null,
NAMESPACE: process.env.NAMESPACE || 'dev',
NODE_ENV: process.env.NODE_ENV || 'development',
SENTRY_DSN: null,
TELEGRAM_BOT_USERNAME: TELEGRAM_BOT_USERNAME,
WEBPACK_BUILD: true // Used by EventCache
})
],
optimization: {
// splitChunks: {
// cacheGroups: {
// app: {
// chunks: 'all',
// name: 'app',
// enforce: true,
// reuseExistingChunk: true,
// }
// }
// },
}
}
if (isProduction) {
config.output.filename = '[name].[hash:8].js'
config.optimization.minimizer = [
new TerserPlugin({ extractComments: false }),
new OptimizeCSSAssetsPlugin({})
]
config.plugins.push(
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: ['app.*.css', 'app.*.js', 'app.*.js.map']
}),
new MiniCssExtractPlugin({ filename: '[name].[hash:8].css' }),
new HtmlWebpackPlugin({
template: 'public/template.html',
inject: false,
filename: 'mainnet.html',
network: 'mainnet',
metaMask: true
}),
new HtmlWebpackPlugin({
template: 'public/template.html',
inject: false,
filename: 'kovan.html',
network: 'kovanTst',
metaMask: true
}),
new HtmlWebpackPlugin({
template: 'public/template.html',
inject: false,
filename: 'rinkeby.html',
network: 'rinkeby',
metaMask: true
}),
new HtmlWebpackPlugin({
template: 'public/template.html',
inject: false,
filename: 'origin.html',
network: 'origin',
metaMask: true
})
)
config.resolve.alias = {
'react-styl': 'react-styl/prod.js'
}
config.module.noParse = [/^(react-styl)$/]
// config.resolve.alias = {
// react: 'react/umd/react.production.min.js',
// 'react-dom': 'react-dom/umd/react-dom.production.min.js',
// 'react-styl': 'react-styl/prod.js',
// web3: path.resolve(__dirname, 'public/web3.min'),
// 'react-router-dom': 'react-router-dom/umd/react-router-dom.min.js'
// }
// config.module.noParse = [
// /^(react|react-dom|react-styl|redux|react-redux|react-router-dom)$/,
// /web3/
// ]
}
module.exports = config