forked from dcaputo-harmoni/open-balena-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
111 lines (109 loc) · 2.74 KB
/
webpack.common.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 webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
require('dotenv').config();
module.exports = {
entry: {
main: [path.join(process.cwd(), 'src/index.js')],
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react'],
},
},
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.svg$/,
type: 'asset', // Use asset module type for SVG
parser: {
dataUrlCondition: {
maxSize: 8 * 1024, // 8kb
},
},
},
{
test: /\.(jpg|png|gif)$/,
type: 'asset/resource', // Use asset module type for images
},
{
test: /\.html$/,
use: {
loader: 'html-loader',
options: {
sources: {
urlFilter: (attribute, value) => !/environment.js$/.test(value),
},
},
},
},
{
test: /\.m?js/,
resolve: {
fullySpecified: false,
},
},
],
},
output: {
path: path.resolve(process.cwd(), 'dist'),
publicPath: '/',
filename: '[name].[contenthash].js',
chunkFilename: '[name].[contenthash].chunk.js',
clean: true, // Automatically clean the output directory before each build
},
optimization: {
moduleIds: 'deterministic', // Enable consistent hashing for long term caching
runtimeChunk: 'single', // Create a runtime file to be shared for all generated chunks
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 0,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name(module) {
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
return `npm.${packageName.replace('@', '')}`;
},
},
},
},
},
plugins: [
new HtmlWebpackPlugin({
inject: true,
publicPath: '.',
template: 'src/index.html',
favicon: 'src/favicon.ico',
manifest: 'src/manifest.json',
}),
new webpack.ProvidePlugin({
process: 'process/browser',
Buffer: ['buffer', 'Buffer'],
}),
],
resolve: {
modules: ['node_modules', 'src'],
extensions: ['.js', '.jsx', '.react.js'],
mainFields: ['browser', 'module', 'main'],
fallback: {
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify'),
vm: false,
},
},
target: ['web', 'es5'],
performance: {
hints: false,
},
};