-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathwebpack.config.ts
83 lines (76 loc) · 1.96 KB
/
webpack.config.ts
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
import path from 'path';
import webpack, { Configuration } from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import DotenvWebpack from 'dotenv-webpack';
import pkgjson from './package.json';
const { NODE_ENV = 'development' } = process.env;
const prod = NODE_ENV === 'production';
const htmlWebpackPluginConfig = {
title: `${pkgjson.name} | ${pkgjson.description}`,
minify: { collapseWhitespace: true },
favicon: 'build/favicon.ico',
};
const plugins: Configuration['plugins'] = [new HtmlWebpackPlugin(prod ? htmlWebpackPluginConfig : undefined)];
if (prod) {
plugins.push(new webpack.EnvironmentPlugin(['INSTAGRAM_ACCESS_TOKEN']));
} else {
plugins.push(new webpack.HotModuleReplacementPlugin(), new DotenvWebpack());
}
function mode(): Configuration['mode'] {
if (NODE_ENV === 'development' || NODE_ENV === 'production') {
return NODE_ENV;
}
return 'none';
}
const config: Configuration = {
mode: mode(),
plugins,
entry: './example/index.tsx',
cache: true,
output: {
path: path.resolve(__dirname, 'build'),
filename: '[name].js',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json', '.mjs'],
alias: {
[pkgjson.name]: path.resolve(__dirname, 'src/index.tsx'),
},
},
module: {
rules: [
{
test: /\.(j|t)sx?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: { plugins: ['react-hot-loader/babel'] },
},
],
},
{
test: /\.css$/,
use: ['style-loader', { loader: 'css-loader' }],
},
],
},
...(prod
? {
optimization: {
splitChunks: {
maxSize: 244000,
cacheGroups: {
vendor: {
test: /node_modules/,
name: 'vendor',
chunks: 'initial',
enforce: true,
},
},
},
},
}
: {}),
};
export default config;