-
Notifications
You must be signed in to change notification settings - Fork 13
/
webpack.config.js
80 lines (74 loc) · 1.94 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
require(`dotenv`).config({ path: `${__dirname}/cloudflare.env` })
const webpack = require(`webpack`)
const CleanWebpackPlugin = require(`clean-webpack-plugin`)
const CloudflareWorkerPlugin = require(`cloudflare-workers-webpack-plugin`)
const {
ALLOWED_ORIGIN = `*`,
ALLOWED_ORIGIN_PATTERNS = ``,
ALWAYS_RETURN_SCORE = false,
CORS_MAXAGE = 300,
RETURN_PW_METADATA = false,
CUSTOM_PW_DICT = ``,
ROUTE_PATTERN,
AUTH_EMAIL,
AUTH_KEY,
ZONE_ID,
SITE_NAME,
} = process.env
if (ALLOWED_ORIGIN_PATTERNS.length) {
const patterns = ALLOWED_ORIGIN_PATTERNS.split(`,`).map(p =>
RegExp(p).toString()
)
console.info(`Allowed origin patterns: ${patterns.join(`, `)}`)
}
module.exports = {
entry: `${__dirname}/src/index.js`,
output: {
path: `${__dirname}/dist`,
filename: `index.js`,
},
target: `webworker`,
mode: `production`,
module: {
rules: [
{
test: /\.js$/,
loader: `babel-loader`,
exclude: [/frequency_lists/],
},
],
},
performance: {
hints: false,
},
node: false,
optimization: {
minimize: false,
},
plugins: [
new CleanWebpackPlugin(`dist/*`, {
root: __dirname,
verbose: false,
}),
new webpack.DefinePlugin({
ALLOWED_ORIGIN: JSON.stringify(ALLOWED_ORIGIN),
ALLOWED_ORIGIN_PATTERNS: JSON.stringify(ALLOWED_ORIGIN_PATTERNS),
ALWAYS_RETURN_SCORE: JSON.stringify(!!ALWAYS_RETURN_SCORE),
CORS_MAXAGE: JSON.stringify(CORS_MAXAGE),
RETURN_PW_METADATA: JSON.stringify(!!RETURN_PW_METADATA),
CUSTOM_PW_DICT: JSON.stringify(CUSTOM_PW_DICT),
LAST_MODIFIED: JSON.stringify(new Date().toJSON()),
}),
new CloudflareWorkerPlugin(AUTH_EMAIL, AUTH_KEY, {
enabled: !process.env.NO_UPLOAD,
zone: ZONE_ID,
site: SITE_NAME,
enabledPatterns: ROUTE_PATTERN,
clearRoutes: false,
skipWorkerUpload: false,
verbose: true,
colors: true,
emoji: true,
}),
],
}