-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwebpack.config.js
103 lines (96 loc) · 2.3 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
98
99
100
101
102
103
const path = require('path');
const merge = require('webpack-merge');
const autoprefixer = require('autoprefixer');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ManifestPlugin = require('webpack-manifest-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const DEV = process.env.NODE_ENV !== 'production';
const BABEL_LOADER = {
test: /.js$/,
loaders: 'babel-loader',
include: path.resolve('src'),
query: {
env: {
development: {
plugins: ['transform-react-display-name'],
},
},
},
exclude: /node_modules/,
};
const LESS_LOADER = {
test: /\.less$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: true,
modules: true,
localIdentName: '[name]-[local]-[hash:base64:5]',
},
},
{
loader: 'postcss-loader',
options: {
sourceMap: 'inline',
plugins: [autoprefixer()],
},
},
{
loader: 'less-loader',
},
],
};
const DEFAULT_CONFIG = {
...(DEV
? { devtool: 'source-map', mode: 'development' }
: { mode: 'production' }),
output: {
filename: '[name].[contentHash].js',
path: path.resolve('dist'),
publicPath: '/assets/',
},
module: {
rules: [BABEL_LOADER, LESS_LOADER],
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].[contentHash].css',
chunkFilename: '[id].[contentHash].css',
}),
new CopyWebpackPlugin([
{
from: path.join(__dirname, 'images'),
to: '[name].[ext]',
toType: 'template',
},
]),
],
};
const CLIENT_CONFIG = merge(DEFAULT_CONFIG, {
entry: { client: path.resolve('src', 'index.js') },
devtool: 'source-map',
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
test: /node_modules/,
chunks: 'initial',
name: 'vendor',
enforce: true,
},
},
},
},
plugins: [new ManifestPlugin({ fileName: 'manifest.client.json' })],
});
const SERVER_CONFIG = merge(DEFAULT_CONFIG, {
target: 'node',
entry: { server: path.resolve('src', 'server.js') },
output: {
libraryTarget: 'commonjs',
},
plugins: [new ManifestPlugin({ fileName: 'manifest.server.json' })],
});
module.exports = [CLIENT_CONFIG, SERVER_CONFIG];