-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
88 lines (83 loc) · 2.32 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
const fs = require('fs')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const truffleConfig = require('./truffle-config.js')
const pages = fs.readdirSync('./src/pages').filter(name => !name.startsWith('.'))
module.exports = function (web3, network, artifacts, confidential) {
let networkConfig = truffleConfig.config[network]
try {
var contract = artifacts.require('GameServerContract')
var address = contract.address
} catch (err) {
console.warn('Warning: No network deployment was detected, so only building singleplayer mode.')
}
let entry = !contract ? { singleplayer : './src/pages/singleplayer/index.js' } : pages.reduce((acc, page) => {
acc[page] = `./src/pages/${page}/index.js`;
return acc;
}, {})
return {
entry,
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader?retainLines=true']
},
{
test: /\.css$/,
exclude: /node_modules/,
use: [ 'style-loader', 'css-loader' ]
},
{
test: /\.(svg|png|jpg|gif)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]'
}
}
]
}
]
},
resolve: {
extensions: ['*', '.js', '.jsx']
},
output: {
path: __dirname + '/dist',
publicPath: './',
filename: '[name].bundle.js'
},
plugins: [
new webpack.DefinePlugin({
'CONTRACT_ADDRESS': JSON.stringify(address || ''),
'WS_ENDPOINT': JSON.stringify(networkConfig.wsEndpoint),
'CONFIDENTIAL_CONTRACT': confidential
}),
new webpack.HotModuleReplacementPlugin(),
...pages.map(page => new HtmlWebpackPlugin({
filename: `${page}.html`,
chunks: [ page ],
template: './src/template.html'
})),
new webpack.LoaderOptionsPlugin({
debug: true
}),
new HtmlWebpackPlugin({
title: 'Oasis Game'
}),
new webpack.NormalModuleReplacementPlugin(/env/, function(resource) {
if (resource.request === 'env') {
resource.request = '../wasm32-shim'
}
})
],
devtool: 'cheap-eval-source-map',
devServer: {
contentBase: './dist',
hot: true
}
}
};