-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathwebpack.config.js
197 lines (192 loc) · 5.55 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
const { readFileSync } = require("fs");
const yaml = require("js-yaml");
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ExtendedDefinePlugin = require("extended-define-webpack-plugin");
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
const CONFIG_YAML = process.env.CONFIG_YAML || "config.yml";
// Take the user config from the file, and override keys with environment variables if they exist
const userConfig = yaml.safeLoad(readFileSync(CONFIG_YAML, "utf8"));
const environmentConfig = [
"GOOGLE_API_KEY",
"ALGOLIA_INDEX_PREFIX",
"ALGOLIA_APPLICATION_ID",
"ALGOLIA_READ_ONLY_API_KEY",
"MOHCD_SUBDOMAIN",
"MOHCD_DOMAIN",
"SFFAMILIES_DOMAIN",
"TESTCAFE_RUNNING",
"LINKSF_DOMAIN",
];
const config = environmentConfig.reduce((acc, key) => {
if (process.env[key] !== undefined) {
acc[key] = process.env[key];
}
return acc;
}, userConfig);
const appRoot = path.resolve(__dirname, "app/");
const buildDir = path.resolve(__dirname, "build");
module.exports = {
mode: process.env.NODE_ENV || "production",
context: __dirname,
entry: ["whatwg-fetch", "@babel/polyfill", path.resolve(appRoot, "init.tsx")],
output: {
path: buildDir,
publicPath: "/dist/",
filename: "bundle.js",
},
resolve: {
extensions: [".tsx", ".ts", ".jsx", ".js"],
alias: {
app: path.resolve(appRoot, ""),
assets: path.resolve(appRoot, "assets"),
actions: path.resolve(appRoot, "actions"),
components: path.resolve(appRoot, "components"),
models: path.resolve(appRoot, "models"),
pages: path.resolve(appRoot, "pages"),
reducers: path.resolve(appRoot, "reducers"),
styles: path.resolve(appRoot, "styles"),
utils: path.resolve(appRoot, "utils"),
},
},
plugins: [
new HtmlWebpackPlugin({
title: "SF Service Guide",
template: "app/index.html",
meta: {
"og:url": "https://sfserviceguide.org",
"og:title": "SF Service Guide | San Francisco",
"twitter:card": "summary_large_image",
"twitter:site": "@sheltertechorg",
"og:description":
"Get guided help finding food, housing, rental assistance, hygiene, health resources, essential services, and more in San Francisco. See the latest updates during the COVID-19 Coronavirus pandemic.",
"og:type": "website",
// Note: The image is specified in the HTML itself because it needs to
// reference an image file.
"og:image:type": "image/png",
"og:image:width": "1200",
"og:image:height": "630",
},
favicon: "app/favicon.ico",
}),
new ExtendedDefinePlugin({
CONFIG: config,
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
}),
new ForkTsCheckerWebpackPlugin(),
new CopyPlugin({
patterns: [{ from: "public", to: path.resolve(__dirname, "public") }],
}),
new NodePolyfillPlugin(),
],
devtool: "source-map",
module: {
rules: [
{
test: /\.(j|t)sx?$/,
use: [
{
loader: "babel-loader",
},
],
exclude: [/node_modules/],
},
{
test: /\.s?css$/,
use: [
"style-loader",
{
loader: "css-loader",
options: {
importLoaders: 1,
modules: {
auto: true,
localIdentName: "[path][name]__[local]--[contenthash:base64:5]",
},
},
},
"sass-loader",
],
},
{
test: /\.(ttf|otf|eot|woff(2)?)(\?[a-z0-9]+)?$/,
type: "asset/resource",
generator: {
filename: "fonts/[name][ext]",
},
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
exclude: [/sf-service-email\.png$/],
type: "asset/resource",
generator: {
filename: "[name]-[contenthash][ext]",
},
use: [
{
loader: "image-webpack-loader",
options: {
gifsicle: {
interlaced: false,
},
optipng: {
optimizationLevel: 7,
},
disable: true,
},
},
],
},
{
test: /sf-service-email\.png$/,
type: "asset/resource",
generator: {
// Do not include content hash so that this has a stable URL
// accessible from email templates.
filename: "[name][ext]",
},
use: [
{
loader: "image-webpack-loader",
options: {
gifsicle: {
interlaced: false,
},
optipng: {
optimizationLevel: 7,
},
disable: true,
},
},
],
},
{
test: /\.pdf$/,
type: "asset/resource",
generator: {
filename: "[name][ext]",
},
include: [path.resolve(__dirname, "app/assets")],
},
],
},
devServer: {
contentBase: buildDir,
historyApiFallback: true,
proxy: {
"/api-docs": {
target: process.env.API_URL || "http://localhost:3000",
},
"/api/v2/": {
target: process.env.API_GO_URL || "http://localhost:3001",
pathRewrite: { "^/api/v2/": "/api/" },
},
"/api/": {
target: process.env.API_URL || "http://localhost:3000",
pathRewrite: { "^/api/": "" },
},
},
},
};