-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
107 lines (95 loc) · 2.38 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
/* eslint-disable import/unambiguous */
const path = require('path');
const webpack = require('webpack');
const HtmlWebPackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const {name: workspaceName} = require('./package.json');
const TARGET = 'web';
const getBuildPath = () => path.resolve(__dirname, 'build');
const getDevtool = (target, env) => {
if (target === 'web' && env === 'development') {
return 'cheap-module-eval-source-map';
}
return 'source-map';
};
const getVendors = (target) => {
let vendors = ['airbnb-js-shims/target/es2015'];
if (target === 'web') {
vendors = [...vendors, 'whatwg-fetch'];
}
return vendors;
};
const getModuleRules = (target, env) => {
let rules = [
{
test: /\.js$/,
use: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
],
},
{
test: /\.scss$/,
use: [
'style-loader',
'css-loader',
'sass-loader',
],
},
{
test: /\.json$/i,
use: [
'json-loader',
],
exclude: /node_modules/,
},
];
return rules;
};
const getPlugins = (target, env) => {
let plugins = [
new webpack.EnvironmentPlugin({
NODE_ENV: 'development',
REACT_APP_TARGET: 'web',
}),
new HtmlWebPackPlugin({
template: './public/index.html',
filename: './index.html',
}),
];
return plugins;
};
module.exports = (env = process.env.NODE_ENV || 'development', target = 'web') => ({
target: TARGET,
devtool: getDevtool(TARGET, env),
entry: {
[workspaceName]: [
...getVendors(TARGET, env),
path.resolve(__dirname, 'src/index.js'),
],
},
output: {
path: getBuildPath(),
filename: `[name].${TARGET}.js`,
},
module: {
rules: [
...getModuleRules(TARGET, env),
],
},
plugins: [
...getPlugins(TARGET, env),
],
stats: {
all: false,
warnings: true,
errors: true,
chunks: true,
timings: true,
},
});