-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
111 lines (107 loc) · 2.92 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
105
106
107
108
109
110
111
const path = require('path');
const HtmlPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const { RelativeCiAgentWebpackPlugin } = require('@relative-ci/agent');
const packageInfo = require('./package.json');
const SRC_DIR = path.resolve(__dirname, 'src');
const OUT_DIR = path.resolve(__dirname, 'dist');
const ARTIFACTS_DIR = path.resolve(__dirname, 'artifacts');
module.exports = (_, options) => {
const { mode = 'production' } = options;
const isProduction = mode === 'production';
return {
context: SRC_DIR,
mode,
entry: './index.jsx',
output: {
path: OUT_DIR,
filename: isProduction ? '[name].[contenthash].js': '[name].js',
assetModuleFilename: isProduction ? '[path][name].[contenthash].[ext]' : '[path][name].[ext]',
hashDigestLength: 8,
},
resolve: {
extensions: ['.jsx', '.js', '.json'],
alias: {
// '@babel/runtime/helpers/esm': '@babel/runtime/helpers/',
},
},
module: {
rules: [
{
test: /\.jsx?$/,
use: 'babel-loader',
include: [SRC_DIR],
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
require('autoprefixer'),
... isProduction ? [require('cssnano')] : [],
],
},
},
},
],
include: [
SRC_DIR,
/node_modules\/antd/,
],
},
{
test: /\.(png|jpe?g|webp|gif)$/,
type: 'asset/resource',
include: [SRC_DIR],
},
{
test: /\.svg$/,
type: 'asset/resource',
include: [path.join(SRC_DIR, 'assets')],
},
{
test: /\.inline.svg$/,
use: ['@svgr/webpack'],
}
],
},
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all'
},
},
},
},
plugins: [
new HtmlPlugin({
title: packageInfo.description,
template: './index.html',
publicPath: '/',
}),
new MiniCssExtractPlugin({
filename: isProduction ? '[name].[contenthash].css': '[name].css',
chunkFilename: isProduction ? '[name].chunk.[contenthash].css': '[name].css',
}),
new CopyPlugin({
patterns: [
{
from: path.resolve(__dirname, 'public'),
},
],
}),
new RelativeCiAgentWebpackPlugin({
payloadFilepath: path.join(ARTIFACTS_DIR, 'relative-ci-payload.json'),
}),
]
};
};