-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack.config.js
104 lines (94 loc) · 2.72 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 webpack = require('webpack');
const BundleAnalyzerPlugin =
require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const path = require('path');
const noop_module_path = path.resolve(__dirname, 'src', 'build', 'noop-module');
module.exports = {
mode: 'production',
devtool: '',
target: 'node',
output: {
filename: 'index.js',
path: path.resolve(__dirname, 'dist')
},
entry: './src/index.js',
resolve: {
alias: {
// Replace with fastestsmallesttextencoderdecoder
'text-encoding$': path.resolve(
__dirname,
'src',
'build',
'text-encoding'
),
// Force webpack to rebuild scratch-sb1-converter
'scratch-sb1-converter$': path.resolve(
__dirname,
'node_modules',
'scratch-sb1-converter',
'index.js'
),
// Remove dead modules
htmlparser2$: noop_module_path,
'canvas-toBlob$': noop_module_path,
'./extension-support/tw-default-extension-urls$': noop_module_path,
'../util/scratch-link-websocket$': noop_module_path
}
},
plugins: [
// Remove extensions
new webpack.NormalModuleReplacementPlugin(
/\/extension-manager$/,
'/src/build/scratch-vm/extension-support/extension-manager'
),
// Remove log
new webpack.NormalModuleReplacementPlugin(
/\/log$/,
'/src/build/scratch-vm/util/log'
),
// Remove I/O modules
new webpack.NormalModuleReplacementPlugin(/^\.\.\/io\//, (resource) => {
resource.request = resource.request.replace(
'..',
'/src/build/scratch-vm'
);
}),
// Remove load-costume and load-sound
new webpack.NormalModuleReplacementPlugin(
/\.\/import\/load-(costume|sound)/,
(resource) => {
resource.request =
'/src/build/scratch-vm/import/load-' +
resource.request.match(/\.\/import\/load-(costume|sound)/)[1];
}
),
// Remove deserialize-assets, serialize-assets, and tw-costume-import-export
new webpack.NormalModuleReplacementPlugin(
/\.\/(?:serialization\/)?(deserialize-assets|serialize-assets|tw-costume-import-export)/,
(resource) => {
resource.request =
'/src/build/scratch-vm/serialization/' +
resource.request.match(
/(deserialize-assets|serialize-assets|tw-costume-import-export)/
)[1];
}
),
// Remove FontManager
new webpack.NormalModuleReplacementPlugin(
/\.\/tw-font-manager$/,
'/src/build/scratch-vm/engine/tw-font-manager'
),
new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false
})
],
module: {
rules: [
{
test: /\.[jt]sx?$/,
loader: 'esbuild-loader'
}
]
}
};