-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
100 lines (94 loc) · 2.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
const path = require("path"),
webpack = require("webpack"),
nodeExternals = require("webpack-node-externals"),
MiniCssExtractPlugin = require("mini-css-extract-plugin"),
CopyWebpackPlugin = require("copy-webpack-plugin"),
dotenv = require("dotenv");
module.exports = () => {
dotenv.config();
// console.log(env);
// console.log(process.env.TMDB_API_KEY);
// console.log(process.env);
// let envKeys = {
// ...process.env,
// 'process.env.TMDB_API_KEY': JSON.stringify(process.env.TMDB_API_KEY),
// 'process.env.PORT': JSON.stringify(process.env.PORT),
// };
// console.log(envKeys, 'PRIMERO');
// if (env) {
// envKeys = Object.keys(env).reduce((prev, next) => {
// prev[`process.env.${next}`] = JSON.stringify(env[next]);
// return prev;
// }, {});
// }
// console.log(envKeys, 'SEGUNDO');
const browserConfig = {
mode: process.env.NODE_ENV === "production" ? "production" : "development",
entry: path.resolve(__dirname, "src", "browser", "index.tsx"),
output: {
path: path.resolve(__dirname, "public"),
filename: "bundle.js",
publicPath: "/",
},
module: {
rules: [
{
test: /\.(tsx|ts)$/,
use: "babel-loader",
exclude: /node_modules/,
},
{
test: /\.js$/,
use: "babel-loader",
},
{
test: /\.(css|sass|scss)$/,
use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"],
},
],
},
resolve: {
extensions: [".ts", ".tsx", ".js"],
},
plugins: [
new webpack.EnvironmentPlugin(["NODE_ENV", "TMDB_API_KEY"]),
new CopyWebpackPlugin({
patterns: [
{ from: "./src/favicon.ico" },
],
}),
new MiniCssExtractPlugin({
filename: "styles.css",
}),
],
};
const serverConfig = {
mode: process.env.NODE_ENV === "production" ? "production" : "development",
entry: path.resolve(__dirname, "src", "server", "index.tsx"),
target: "node",
externals: [nodeExternals()],
output: {
path: __dirname,
filename: "server.js",
publicPath: "/",
},
module: {
rules: [
{
test: /\.(tsx|ts)$/,
use: "babel-loader",
exclude: /node_modules/,
},
{
test: /\.js$/,
use: "babel-loader",
},
],
},
resolve: {
extensions: [".ts", ".tsx", ".js"],
},
plugins: [new webpack.EnvironmentPlugin(["NODE_ENV", "TMDB_API_KEY"])],
};
return [browserConfig, serverConfig];
};