generated from gilamran/fullstack-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
115 lines (109 loc) · 2.95 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
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
import path from 'path';
import { Configuration } from 'webpack';
import { WebpackManifestPlugin } from 'webpack-manifest-plugin';
import cssnano from 'cssnano';
import { SERVER_PORT, IS_DEV, WEBPACK_PORT } from './src/server/config';
const plugins = [new WebpackManifestPlugin({})];
// import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
// plugins.push(new BundleAnalyzerPlugin());
const nodeModulesPath = path.resolve(__dirname, 'node_modules');
const targets = IS_DEV ? { chrome: '79', firefox: '72' } : '> 0.25%, not dead';
const config: Configuration = {
mode: IS_DEV ? 'development' : 'production',
devtool: IS_DEV ? 'inline-source-map' : false,
entry: ['./src/client/client'],
output: {
path: path.join(__dirname, 'dist', 'statics'),
filename: `[name]-[chunkhash]-bundle.js`,
chunkFilename: '[name]-[chunkhash]-bundle.js',
publicPath: '/statics/',
},
resolve: {
extensions: ['.js', '.ts', '.tsx'],
},
optimization: {
minimize: !IS_DEV,
splitChunks: {
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
priority: 10,
},
material: {
test: /[\\/]node_modules[\\/]@material-ui[\\/]/,
name: 'material-ui',
chunks: 'all',
priority: 20,
},
},
},
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: [/node_modules/, nodeModulesPath],
use: {
loader: 'babel-loader',
options: {
presets: [['@babel/env', { modules: false, targets }], '@babel/react', '@babel/typescript'],
plugins: [
'@babel/proposal-numeric-separator',
'@babel/plugin-transform-runtime',
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-proposal-class-properties'],
'@babel/plugin-proposal-object-rest-spread',
],
},
},
},
{
test: /\.m?js/,
resolve: {
fullySpecified: false,
},
},
{
test: /\.css$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
options: {
modules: true,
localsConvention: 'camelCase',
sourceMap: IS_DEV,
},
},
{
loader: 'postcss-loader',
options: {
sourceMap: IS_DEV,
plugins: IS_DEV ? [cssnano()] : [],
},
},
],
},
{
test: /.jpe?g$|.gif$|.png$|.svg$|.woff$|.woff2$|.ttf$|.eot$/,
use: 'url-loader?limit=10000',
},
],
},
devServer: {
port: WEBPACK_PORT,
overlay: IS_DEV,
open: IS_DEV,
openPage: `http://localhost:${SERVER_PORT}`,
},
plugins,
externals: {
react: 'React',
'react-dom': 'ReactDOM',
},
};
export default config;