-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.babel.js
96 lines (92 loc) · 2.52 KB
/
webpack.config.babel.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
/* eslint-disable @typescript-eslint/explicit-function-return-type */
import HtmlWebPackPlugin from 'html-webpack-plugin'
import webpack from 'webpack'
import DashboardPlugin from 'webpack-dashboard/plugin'
import InlineChunkHtmlPlugin from 'react-dev-utils/InlineChunkHtmlPlugin'
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'
import dotenv from 'dotenv'
// Setup env vars
dotenv.config()
const isProduction = process.env.NODE_ENV == 'production'
const baseUrl = '/'
module.exports = ({ stats = false } = {}) => ({
devtool: 'eval-source-map',
output: {
path: __dirname + '/dist',
chunkFilename: isProduction ? '[name].[chunkhash:4].js' : '[name].js',
filename: isProduction ? '[name].[chunkhash:4].js' : '[name].js',
publicPath: baseUrl,
},
module: {
rules: [
{
test: /\.(png|svg|jpg|gif)$/,
use: ['file-loader'],
},
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: { cacheDirectory: true },
},
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: { cacheDirectory: true },
},
{
loader: 'ts-loader',
options: {
// disable type checker - we will use it in fork plugin
transpileOnly: true,
},
},
],
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
],
},
devServer: {
historyApiFallback: true,
},
resolve: {
alias: {
'react-dom': '@hot-loader/react-dom',
},
modules: ['src', 'node_modules'],
extensions: ['.ts', '.tsx', '.js'],
},
plugins: [
new HtmlWebPackPlugin({
template: './src/html/index.html',
title: 'ts-react',
}),
isProduction && new InlineChunkHtmlPlugin(HtmlWebPackPlugin, [/runtime/]),
new webpack.EnvironmentPlugin({
NODE_ENV: 'development',
BASE_URL: baseUrl,
}),
new ForkTsCheckerWebpackPlugin({ silent: stats }),
isProduction && new DashboardPlugin(),
// define inside one plugin instance
new webpack.DefinePlugin({
VERSION: JSON.stringify(require('./package.json').version),
// MOCK: Use mock or real API implementation
'process.env.MOCK': JSON.stringify(process.env.MOCK || 'false'),
}),
].filter(Boolean),
optimization: {
splitChunks: {
chunks: 'all',
},
runtimeChunk: true,
},
})