-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
81 lines (75 loc) · 1.91 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
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { resolve } = require('path');
const { NODE_ENV } = process.env;
const SRC_DIR = resolve(__dirname, 'src');
const BUILD_DIR = resolve(__dirname, 'build');
const PUBLIC_DIR = resolve(__dirname, 'public');
const DEV_API_PROXY_URL = 'http://localhost:3001';
const PRODUCTION = NODE_ENV === 'production';
const plugins = [
new HtmlWebpackPlugin({
title: 'React TS Starter Kit',
template: resolve(PUBLIC_DIR, 'index.ejs'),
}),
];
if (PRODUCTION) {
plugins.push(new MiniCssExtractPlugin({ filename: '[name].css' }));
}
module.exports = {
mode: PRODUCTION ? 'production' : 'development',
entry: [resolve(SRC_DIR, 'index.tsx')],
output: {
path: BUILD_DIR,
filename: '[name].bundle.js',
publicPath: '/',
},
resolve: {
extensions: ['.ts', '.tsx', '.mjs', '.js', '.json', '.jsx'],
},
devtool: PRODUCTION ? 'hidden-source-map' : 'eval-source-map',
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/,
options: {
configFile: PRODUCTION ? 'tsconfig.build.json' : 'tsconfig.json',
onlyCompileBundledFiles: true,
},
},
{
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
loader: 'url-loader',
options: {
limit: 8192,
},
},
{
test: /\.css$/,
use: [
PRODUCTION
? MiniCssExtractPlugin.loader
: {
loader: 'style-loader',
options: {
insertAt: 'top',
},
},
'css-loader',
],
},
],
},
plugins,
devServer: {
compress: true,
port: 9000,
historyApiFallback: true,
proxy: {
'/api': DEV_API_PROXY_URL,
'/graphql': DEV_API_PROXY_URL,
},
},
};