-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
125 lines (119 loc) · 3.19 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
116
117
118
119
120
121
122
123
124
125
const path = require('path');
const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
const cssnano = require('cssnano');
const { SERVER_PORT, IS_DEV, WEBPACK_PORT } = require('./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 = { chrome: '79', firefox: '72' };
const config = {
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', '.scss'],
alias: {
'/client': path.resolve(__dirname, './src/client'),
'/shared': path.resolve(__dirname, './src/shared'),
},
},
optimization: {
minimize: !IS_DEV,
splitChunks: {
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
priority: 10,
}
},
},
},
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', { loose: true }],
'@babel/plugin-proposal-object-rest-spread',
],
},
},
},
{
test: /\.m?js/,
resolve: {
fullySpecified: false,
},
},
{
test: /\.s[ac]ss$/i,
use: [
// Creates `style` nodes from JS strings
"style-loader",
// Translates CSS into CommonJS
"css-loader",
// Compiles Sass to CSS
{
loader: "sass-loader",
options: {
sourceMap: IS_DEV
}
}
],
},
{
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: {},
};
module.exports = config;