-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwebpack.config.js
178 lines (170 loc) · 4.59 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
const path = require("path");
const webpack = require("webpack");
const CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin");
const RobotstxtPlugin = require("robotstxt-webpack-plugin").default;
const OpenBrowserPlugin = require('open-browser-webpack-plugin');
const { mapValues, keys } = require("lodash");
const isProduction = process.env.NODE_ENV === "production";
const dotenv = require("dotenv");
const envs = updateParsedEnvsWithProcessEnvs(dotenv.load().parsed);
// we are combining the NODE_ENV variable with the local variables from the .env file
// we can't simply pass all envs from process.env because they would become part of the bundle
const allEnvs = mapValues(
Object.assign(
{},
{
NODE_ENV: process.env.NODE_ENV || "development",
},
envs
),
JSON.stringify
);
console.log("Using envs:", allEnvs);
const devEntryPoints = isProduction
? []
: [
"react-hot-loader/patch",
"webpack-dev-server/client?https://localhost:9090",
"webpack/hot/only-dev-server",
];
module.exports = {
resolve: {
extensions: [".ts", ".tsx", ".js"],
},
devServer: {
contentBase: path.join(__dirname, "dist"),
host: "localhost",
port: 9090,
historyApiFallback: {
verbose: true,
rewrites: [
{ from: /^\/commit/, to: '/commit.html' }
]
},
// respond to 404s with index.html
hot: true,
// display errors on page
overlay: true,
// enable HMR on the server
proxy: {
"/node": {
target: "http://localhost:8545",
pathRewrite: { "^/node": "" },
},
"/pdfrenderer": {
target: "https://neufund.net/pdfrender/",
pathRewrite: { "^/pdfrenderer": "" },
changeOrigin: true
},
},
staticOptions: {
extensions: ['html'],
}
},
entry: {
main: [...devEntryPoints, "./app/index.tsx"],
commit: [...devEntryPoints, "./app/commit.tsx"],
page: "./page/ts/index.ts",
},
output: {
path: path.resolve(__dirname, "dist"),
filename: isProduction ? "[name]-[hash].js" : "[name].js",
},
devtool: isProduction ? "(none)" : "inline-source-map",
plugins: [
new webpack.HotModuleReplacementPlugin(),
new CommonsChunkPlugin({ name: "common", chunks: ["main", "commit"] }),
new webpack.NamedModulesPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery",
}),
new RobotstxtPlugin({
policy: [
{
userAgent: "*",
allow: "/",
},
],
}),
new webpack.DefinePlugin({
"process.env": allEnvs,
}),
],
node: {
__filename: true,
},
module: {
rules: [
{
test: /\.s?css$/,
use: [
{ loader: "style-loader" },
{
loader: "css-loader",
options: {
minimize: isProduction,
importLoaders: 1,
modules: true,
localIdentName: "[name]__[local]___[hash:base64:5]",
camelCase: "dashesOnly",
},
},
{ loader: "sass-loader" },
],
},
{ test: /\.json$/, use: "json-loader" },
{
test: /\.(tsx?|jsx?)$/,
loader: "awesome-typescript-loader",
exclude: {
test: path.resolve(__dirname, 'node_modules'),
exclude: [
path.resolve(__dirname, 'node_modules/eth-sig-util'),
path.resolve(__dirname, 'node_modules/web3-provider-engine'),
path.resolve(__dirname, 'node_modules/replace-string'),
path.resolve(__dirname, 'node_modules/ledger-wallet-provider/node_modules/web3-provider-engine'),
]
},
},
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" },
{
test: /\.(jpg|png|svg)$/,
loader: "url-loader",
options: {
limit: 25000,
publicPath: '/'
},
},
{
test: /\.(ttf|eot|otf)$/,
loader: "file-loader",
options: {
name: "fonts/[hash].[ext]",
},
},
],
},
};
if (isProduction) {
module.exports.plugins.push(
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: { warnings: false },
})
);
} else {
module.exports.plugins.push(
new OpenBrowserPlugin({ url: 'https://localhost:9090/' })
)
}
function updateParsedEnvsWithProcessEnvs(envs){
const processEnvs = process.env;
const result = {};
keys(envs).forEach(k => {
result[k] = (k in processEnvs)? processEnvs[k] : envs[k];
});
return result;
}