-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
80 lines (78 loc) · 2.34 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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
function relpath(fp) {
return path.resolve(__dirname, ...fp.split('/'));
}
module.exports = {
// note: production disables the in-memory cache
mode: 'development', // 'production',
entry: {
index: relpath('src/index.tsx'),
},
// enable source mapping (disable for much smaller files)
devtool: 'inline-source-map',
// auto-generate index.html file with webpack bundles
plugins: [
new HtmlWebpackPlugin({
title: 'Example Webapp',
template: relpath('src/index.html'),
}),
],
output: {
clean: true,
filename: '[name].[contenthash].bundle.js',
path: relpath('dist'),
},
devServer: {
static: relpath('dist'),
},
optimization: {
runtimeChunk: 'single',
// enable caching with vendors in a seperate chunk
moduleIds: 'deterministic',
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
},
},
},
},
performance: {
// hides the performance warnings for now
// these are especially apparent with source maps enabled
hints: false,
},
module: {
rules: [
// typescript support
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
// sass support with `import './styles.scss'`
{
test: /\.s[ac]ss$/i,
use: ['style-loader', 'css-loader', 'sass-loader'],
},
// css support with `import './styles.css'`
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
// image support with `import Image from './image.png'`
{
test: /\.(png|svg|jpe?g|gif)$/i,
use: [{ loader: 'file-loader' }],
},
],
},
resolve: {
// need '.tsx', '.ts' for typescript support
// need to include '.js' for webpack-dev-server resolutions, even with typescript support
extensions: ['.tsx', '.ts', '.js'],
},
};