-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
107 lines (104 loc) · 2.69 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
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 SRC_DIR = path.resolve(__dirname, 'src');
const OUT_DIR = path.resolve(__dirname, 'dist');
const ARTIFACTS_DIR = path.resolve(__dirname, 'artifacts');
module.exports = (_, { mode }) => {
const isProduction = mode === 'production';
return {
context: SRC_DIR,
entry: './index.jsx',
output: {
path: OUT_DIR,
filename: isProduction ? '[name].[contenthash:5].js': '[name].js',
},
resolve: {
extensions: ['.jsx', '.js', '.json'],
alias: {
'@babel/runtime/helpers/esm': '@babel/runtime/helpers/',
},
},
module: {
rules: [
{
test: /\.jsx?$/,
loader: 'babel-loader',
include: [SRC_DIR],
},
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: !isProduction,
},
},
'css-loader',
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
require('autoprefixer'),
... isProduction ? [require('cssnano')] : [],
],
},
},
},
],
include: [SRC_DIR],
},
{
test: /\.(png|jpe?g|webp|gif)$/,
loader: 'file-loader',
options: {
name: isProduction ? '[path][name].[contenthash:5].[ext]' : '[path][name].[ext]',
},
include: [SRC_DIR],
},
{
test: /\.inline.svg$/,
use: ['@svgr/webpack'],
}
],
},
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all'
},
},
},
},
plugins: [
new HtmlPlugin({
template: './index.html',
filename: 'index.html',
}),
new MiniCssExtractPlugin({
filename: isProduction ? '[name].[contenthash:5].css': '[name].css',
}),
new CopyPlugin({
patterns: [
{
from: path.resolve(__dirname, 'public'),
},
],
}),
new RelativeCiAgentWebpackPlugin({
payloadFilepath: path.join(ARTIFACTS_DIR, 'relative-ci-payload.json'),
}),
],
devServer: {
hot: true,
inline: true
}
};
};