-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
86 lines (77 loc) · 2.45 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
const path = require('path');
const webpack = require('webpack');
// Use .env in development mode, .env.production in production mode
const dotenvfile = process.env.NODE_ENV === 'production' ? '.env.production' : '.env';
// call dotenv and it will return an Object with a parsed key
const environ = require('dotenv').config({ path: dotenvfile }).parsed;
// reduce it to a nice object, the same as before
const envKeys = Object.keys(environ).reduce((prev, next) => {
// eslint-disable-next-line no-param-reassign
prev[`process.env.${next}`] = JSON.stringify(environ[next]);
return prev;
}, {});
envKeys['process.env.NODE_ENV'] = JSON.stringify(process.env.NODE_ENV);
module.exports = (env) => {
// We can have two prod types
// 1. app -> To generate the build for the app
// 2. user -> To generate the build for users
const outputPath =
env.type === 'user'
? path.resolve(__dirname, 'backend', 'user', 'build')
: path.resolve(__dirname, 'backend', 'public', 'build');
const entryFile =
env.type === 'user'
? path.join(__dirname, 'frontend', 'userIndex.jsx')
: path.join(__dirname, 'frontend', 'index.jsx');
const publicPath = env.type === 'user' ? 'public/' : '/';
envKeys['process.env.TYPE'] = JSON.stringify(env.type);
envKeys['process.env.PUBLIC_URL'] = JSON.stringify(publicPath);
const ignoreWatchOptions =
env.type === 'app' ? [/node_modules/, /\user.(\w+).js(x?)/i] : [/node_modules/];
return {
entry: entryFile,
output: {
filename: 'bundle.js',
path: outputPath,
publicPath,
},
node: {
fs: 'empty',
},
watchOptions: {
ignored: ignoreWatchOptions,
},
module: {
rules: [
{
test: /redux$/,
resolve: {
mainFields: ['module', 'main', 'unpkg'],
},
},
{
test: /\.js(x?)$/,
exclude: [/node_modules/],
use: [{ loader: 'babel-loader' }],
},
{
test: /\.js(x?)$/,
exclude: [/node_modules/, /\user.(\w+).js(x?)/i],
use: [{ loader: 'eslint-loader' }],
},
{
test: [/\.s[ac]ss$/i, /\.css$/i],
use: [
// style-loader
{ loader: 'style-loader' },
// css-loader
{ loader: 'css-loader' },
// sass-loader
{ loader: 'sass-loader' },
],
},
],
},
plugins: [new webpack.DefinePlugin(envKeys)],
};
};