forked from italia/api-oas-checker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
104 lines (101 loc) · 3.04 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 { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const webpack = require('webpack');
const packageJson = require('./package.json');
const srcPath = path.resolve(__dirname, 'src');
const buildPath = path.resolve(__dirname, 'dist');
const isProduction = process.env.NODE_ENV === 'production';
const optimization = isProduction
? {
minimizer: [
// `...` is the webpack@5 syntax to extend existing minimizers (i.e. `terser-webpack-plugin`)
`...`,
new CssMinimizerPlugin(),
],
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/](monaco-editor)[\\/]/, // monaco-editor has a huge bundle size
name: 'vendor',
chunks: 'all',
},
},
},
}
: {};
module.exports = {
entry: `${srcPath}/index.js`,
devtool: isProduction ? false : 'source-map',
devServer: {
static: buildPath,
open: true,
compress: true,
hot: true,
port: 3000,
host: '0.0.0.0', // To expose contents via docker
},
mode: isProduction ? 'production' : 'development',
module: {
rules: [
{ test: /\.(m)?js$/, use: ['babel-loader'], exclude: /node_modules/ },
{
test: /\.(s)?css$/,
use: [isProduction ? MiniCssExtractPlugin.loader : 'style-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.(woff(2)?|ico|png|jpg|jpeg|svg|ttf)$/i,
type: 'asset',
generator: { filename: '[name].[contenthash][ext]' },
},
],
},
optimization,
output: {
filename: '[name].[contenthash].js',
path: buildPath,
publicPath: '',
},
performance: {
maxEntrypointSize: 512000,
maxAssetSize: 512000,
},
plugins: [
// Removes/cleans build folders and unused assets when rebuilding
new CleanWebpackPlugin(),
new CopyWebpackPlugin({
patterns: [
{ from: 'public', to: '.' },
{ from: 'spectral*.yml', to: '.' },
{ from: 'spectral*.doc.html', to: '.' },
],
}),
new webpack.DefinePlugin({
REPO_URL: JSON.stringify(packageJson.repository),
VERSION: JSON.stringify(packageJson.version),
}),
new HtmlWebpackPlugin({
template: `${srcPath}/index.html`,
filename: 'index.html',
}),
// Extracts CSS into separate files
new MiniCssExtractPlugin({ filename: '[name].[contenthash].css' }),
new MonacoWebpackPlugin({
languages: ['yaml'],
}),
],
resolve: {
extensions: ['.js', '.json'],
fallback: {
vm: false,
fs: false,
},
},
// https://github.com/webpack/webpack-dev-server/issues/2758#issuecomment-706840237
// https://webpack.js.org/configuration/target/
target: isProduction ? 'browserslist' : 'web',
};