-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.client.js
97 lines (96 loc) · 2.36 KB
/
webpack.client.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 ReactLoadableSSRAddon = require('react-loadable-ssr-addon');
const ExtractCssChunks = require('extract-css-chunks-webpack-plugin');
module.exports = {
target: 'web',
entry: {
index: './src/index.js',
},
output: {
publicPath: '/dist/',
filename: '[name].js', // name for file with common logic
chunkFilename: '[name].chunk.js', // name for logic chunks
path: path.join(__dirname, 'dist'),
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
babelrc: false,
presets: ['@babel/preset-env', '@babel/preset-react'],
plugins: [
// the plugin need for working with dynamic imports
'@babel/plugin-syntax-dynamic-import',
// the plugin need for working with react-loadable library
'react-loadable/babel',
],
},
},
},
{
test: /\.(gif|jpe?g|png|ico)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 10000,
},
},
],
},
{
test: /\.(otf|eot|svg|ttf|woff|woff2).*$/,
use: [
{
loader: 'url-loader',
options: {
limit: 10000,
},
},
],
},
// this say that for css handling need to use ExtractCssChunks loader by default
{
test: /\.css$/,
use: [
{
loader: ExtractCssChunks.loader,
},
'css-loader',
],
},
],
},
optimization: {
nodeEnv: 'development', // NODE_ENV
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
minChunks: 2,
},
default: {
minChunks: 2,
reuseExistingChunk: true,
},
},
},
},
plugins: [
// the plugin need for creating chunks scheme
new ReactLoadableSSRAddon({
filename: 'react-loadable-ssr-addon.json',
}),
// the plugin need for naming css chunks
new ExtractCssChunks({
filename: '[name].css', // name for common styles
chunkFilename: '[name].chunk.css', // names for styles chunks
}),
],
};