forked from Flexget/webui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
135 lines (126 loc) · 3.14 KB
/
webpack.config.js
File metadata and controls
135 lines (126 loc) · 3.14 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const path = require('path');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const webpack = require('webpack');
const __DEBUG__ = !!process.env.DEBUG;
const __DEV__ = process.env.NODE_ENV !== 'production';
const mode = __DEV__ ? 'development' : 'production';
const entry = {
main: [...(__DEV__ ? ['react-hot-loader/patch'] : []), 'whatwg-fetch', './src/app.tsx'],
};
const output = {
path: __DEV__ ? __dirname : path.join(__dirname, 'dist', 'assets'),
filename: __DEV__ ? '[name].bundle.js' : '[name].[chunkhash].js',
publicPath: __DEV__ ? '/' : 'assets/',
globalObject: 'this',
};
const htmlConfig = {
title: 'FlexGet Manager',
template: './src/index.ejs',
};
if (__DEV__) {
htmlConfig.base = '/';
} else {
htmlConfig.filename = '../index.html';
htmlConfig.base = `{{ base_url }}/`;
}
const plugins = [
new webpack.DefinePlugin({ __DEV__ }),
new ForkTsCheckerWebpackPlugin({
tsconfig: path.resolve('tsconfig.json'),
}),
new HtmlWebpackPlugin(htmlConfig),
...(__DEV__
? [new webpack.HotModuleReplacementPlugin()]
: [
new MiniCssExtractPlugin({
filename: '[name].[chunkhash].css',
allChunks: true,
}),
]),
...(__DEBUG__
? [
new BundleAnalyzerPlugin({
analyzerMode: 'server',
}),
]
: []),
];
const config = {
mode,
entry,
output,
plugins,
devtool: __DEV__ ? 'eval-source-map' : 'source-map',
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
modules: [path.resolve('./src'), 'node_modules'],
alias: {
'react-dom': '@hot-loader/react-dom',
},
},
optimization: {
sideEffects: true,
splitChunks: {
cacheGroups: {
default: {
chunks: 'async',
minChunks: 2,
},
vendors: {
test: /[\\/]node_modules[\\/]/,
chunks: 'initial',
},
},
},
},
module: {
rules: [
{
test: /\.(t|j)sx?$/,
loaders: [
'babel-loader',
{
loader: 'ts-loader',
options: {
transpileOnly: true,
happyPackMode: true,
},
},
],
exclude: /node_modules/,
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff',
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader',
},
{
test: /\.(gif|png|jpg|jpeg)(\?[a-z0-9]+)?$/,
loader: 'url-loader?limit=8192',
},
{
test: /\.css$/,
use: [
...(__DEV__
? ['style-loader']
: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '',
},
},
]),
'css-loader',
],
},
],
},
};
module.exports = config;