forked from kriasoft/graphql-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
75 lines (64 loc) · 1.76 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
/**
* Webpack configuration
*
* @see https://webpack.js.org/configuration/
* @copyright 2016-present Kriasoft (https://git.io/vMINh)
*/
const env = require("env");
const path = require("path");
const { DefinePlugin } = require("webpack");
const pkg = require("./package.json");
/**
* @param {Record<string, boolean> | undefined} envName
* @param {{ mode: "production" | "development" }} options
* @returns {import("webpack").Configuration}
*/
module.exports = function config(envName, options) {
const isEnvProduction = options.mode === "production";
const isEnvDevelopment = options.mode === "development";
const prodEnv = env.load("prod");
const testEnv = env.load("test");
const devEnv = env.load("dev");
process.env.BABEL_ENV = options.mode;
return {
mode: options.mode,
target: "webworker",
bail: isEnvProduction,
entry: "./main.ts",
output: {
path: path.resolve(__dirname, "../dist"),
pathinfo: isEnvDevelopment,
filename: `${pkg.name}.js`,
},
resolve: {
extensions: [".ts"],
},
optimization: {
minimize: isEnvProduction,
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: "babel-loader",
options: {
rootMode: "upward",
cacheDirectory: `../.cache/${pkg.name}.babel-loader`,
cacheCompression: true,
},
},
],
},
plugins: [
new DefinePlugin({
GOOGLE_CLOUD_REGION: JSON.stringify(prodEnv.GOOGLE_CLOUD_REGION),
GOOGLE_CLOUD_PROJECT: JSON.stringify({
prod: prodEnv.GOOGLE_CLOUD_PROJECT,
test: testEnv.GOOGLE_CLOUD_PROJECT,
dev: devEnv.GOOGLE_CLOUD_PROJECT,
}),
}),
],
};
};