This repository has been archived by the owner on Nov 22, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
webpack.config.js
157 lines (145 loc) · 4.08 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
const glob = require('glob')
const path = require('path')
const webpack = require('webpack')
const CopyPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const WebpackBundleAnalyzer = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
module.exports = {
mode: process.env.NODE_ENV || 'production',
devtool: 'source-map',
devServer: {
hot: 'only',
port: process.env.PORT || 30443,
static: './dist',
// devMiddleware: { writeToDisk: true },
allowedHosts: ['localhost', '.web3os.dev', '.web3os.local'],
client: {
logging: 'info',
// progress: true
},
server: {
type: 'https',
options: {
cert: './src/assets/ssl/web3os.dev.crt',
key: './src/assets/ssl/web3os.dev.key'
}
}
},
performance: {
hints: false
},
experiments: {
topLevelAwait: true,
asyncWebAssembly: true
// lazyCompilation: true
},
plugins: [
// new WebpackBundleAnalyzer(),
new webpack.NormalModuleReplacementPlugin(/node:/, resource => {
const mod = resource.request.replace(/^node:/, '')
switch (mod) {
case 'path':
resource.request = 'path-browserify'
break
default:
throw new Error(`Not found ${mod}`)
}
}),
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
process: 'process/browser'
}),
new HtmlWebpackPlugin({
favicon: 'src/assets/favicon.ico',
template: './src/index.html',
chunks: ['_loader']
}),
new CopyPlugin({
patterns: [
{ from: 'manifest.json' },
{ from: 'src/assets/dosbox' },
{ from: 'src/assets/icon-512.png', to: 'assets/icon.png' },
{ from: 'src/assets/icon-192.png', to: 'assets' },
{ from: 'src/assets/maskable_icon_x192.png', to: 'assets' }
]
})
],
entry: {
_loader: './src/_loader.js',
kernel: './src/kernel.js',
'service-worker': './src/service-worker.js',
...glob.sync('./src/modules/**/*.js').reduce((obj, el) => { obj['modules/' + path.parse(el).dir.split('/').at(-1)] = el; return obj }, {})
},
output: {
clean: true,
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
devtoolModuleFilenameTemplate: 'file:///[absolute-resource-path]',
publicPath: ''
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
fallback: {
assert: require.resolve('assert'),
buffer: require.resolve('buffer'),
os: require.resolve('os-browserify/browser'),
url: require.resolve('url/'),
path: require.resolve('path-browserify'),
http: require.resolve('stream-http'),
https: require.resolve('https-browserify'),
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify'),
process: require.resolve('process/browser'),
util: require.resolve('util')
}
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
},
{ // We're gonna slowly transition to typescript..
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader']
},
{
test: /\.(md|txt)$/i,
use: 'raw-loader'
},
{
test: /\.(gif|mp3|wav|mp4|ogg|jsdos|img|bin|zst|iso)$/i,
type: 'asset/resource'
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource'
},
{
test: /\.(png|jpe?g|webp|svg|)$/i,
use: [
{
loader: 'img-optimize-loader',
options: {
compress: {
mode: 'lossless',
disableOnDevelopment: true
}
}
}
]
}
]
}
}