forked from sugarshin/react-instagram-embed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
97 lines (91 loc) · 2.15 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
const path = require('path');
const webpack = require('webpack');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const pkg = require('./package.json');
const { PORT = 8080, NODE_ENV = 'development' } = process.env;
const prod = NODE_ENV === 'production';
const htmlWebpackPluginConfig = {
title: `${pkg.name} | ${pkg.description}`,
minify: { collapseWhitespace: true },
favicon: 'build/favicon.ico',
};
const entry = [
'@babel/polyfill',
'./example/index.tsx',
];
const plugins = [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
},
}),
new HtmlWebpackPlugin(prod ? htmlWebpackPluginConfig : undefined),
];
if (!prod) {
plugins.push(
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin()
);
}
module.exports = {
mode: NODE_ENV,
plugins,
entry,
cache: true,
output: {
path: path.resolve(__dirname, 'build'),
filename: 'bundle.js',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json', '.mjs'],
alias: {
[pkg.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'] }, // TODO: if write to .babelrc then become test fails
},
{
loader: 'awesome-typescript-loader',
options: { configFileName: 'tsconfig.demo.json' },
},
],
},
{
test: /\.css$/,
use: ['style-loader', { loader: 'css-loader' }],
},
],
},
...(prod ? {
optimization: {
minimizer: [new UglifyJsPlugin()],
splitChunks: {
maxSize: 244000,
cacheGroups: {
vendor: {
test: /node_modules/,
name: 'vendor',
chunks: 'initial',
enforce: true,
},
},
},
},
} : {}),
devServer: {
contentBase: './example',
hot: true,
publicPath: '/',
host: '0.0.0.0',
port: PORT,
},
};