forked from tot-ra/graphql-schema-registry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
104 lines (96 loc) · 1.99 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
104
const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const config = (env) => ({
output: {
path: path.resolve('./dist/assets'),
filename: '[name].js',
libraryTarget: 'umd',
chunkFilename: '[name].[contenthash].js',
crossOriginLoading: 'anonymous',
pathinfo: true,
},
module: {
rules: [
{
test: /.jsx?$/,
use: {
loader: 'babel-loader',
},
include: [path.resolve(__dirname, './client')],
},
{
test: /\.(png|jpg|svg)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]',
},
},
{
test: /\.(p|post)?css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
],
},
resolve: {
extensions: ['.js', '.jsx', '.json'],
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].css?v=[contenthash]',
}),
],
});
function createConfigDev(name, entry) {
return {
mode: 'development',
name,
entry: {
[name]: [
`webpack-hot-middleware/client?path=/__webpack_hmr&reload=true&name=${name}`,
entry,
],
},
stats: 'minimal',
devtool: 'eval-cheap-source-map',
plugins: [new webpack.HotModuleReplacementPlugin()],
};
}
function createConfigProd(name, entry) {
return {
mode: 'production',
entry: {
[name]: [entry],
},
optimization: {
namedModules: true,
namedChunks: true,
minimizer: [
new TerserPlugin({
parallel: true,
sourceMap: false,
}),
],
},
plugins: [new OptimizeCssAssetsPlugin()],
};
}
const standalone = {
dev: createConfigDev(
'management-ui-standalone',
'./client/entry-standalone.jsx'
),
prod: createConfigProd(
'management-ui-standalone',
'./client/entry-standalone.jsx'
),
};
module.exports = (env) => [
merge(
config(env),
env && env.production ? standalone.prod : standalone.dev
),
];