forked from scratchfoundation/scratch-vm
-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
webpack.config.js
139 lines (137 loc) · 4.14 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
const CopyWebpackPlugin = require('copy-webpack-plugin');
const defaultsDeep = require('lodash.defaultsdeep');
const path = require('path');
const base = {
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
devServer: {
contentBase: false,
host: '0.0.0.0',
port: process.env.PORT || 8073
},
devtool: 'cheap-module-source-map',
output: {
library: 'VirtualMachine',
filename: '[name].js'
},
module: {
rules: [{
test: /\.js$/,
loader: 'babel-loader',
include: path.resolve(__dirname, 'src'),
query: {
presets: [['@babel/preset-env']]
}
},
{
test: /\.mp3$/,
loader: 'file-loader',
options: {
outputPath: 'media/music/'
}
}]
},
plugins: []
};
module.exports = [
// Web-compatible
defaultsDeep({}, base, {
target: 'web',
entry: {
'scratch-vm': './src/index.js',
'scratch-vm.min': './src/index.js'
},
output: {
libraryTarget: 'umd',
path: path.resolve('dist', 'web')
},
module: {
rules: base.module.rules.concat([
{
test: require.resolve('./src/index.js'),
loader: 'expose-loader?VirtualMachine'
}
])
}
}),
// Node-compatible
defaultsDeep({}, base, {
target: 'node',
entry: {
'scratch-vm': './src/index.js'
},
output: {
libraryTarget: 'commonjs2',
path: path.resolve('dist', 'node')
},
externals: {
'decode-html': true,
'format-message': true,
'htmlparser2': true,
'immutable': true,
'scratch-parser': true,
'socket.io-client': true,
'text-encoding': true
}
}),
// Playground
defaultsDeep({}, base, {
target: 'web',
entry: {
'benchmark': './src/playground/benchmark',
'video-sensing-extension-debug': './src/extensions/scratch3_video_sensing/debug'
},
output: {
path: path.resolve(__dirname, 'playground'),
filename: '[name].js'
},
module: {
rules: base.module.rules.concat([
{
test: require.resolve('./src/index.js'),
loader: 'expose-loader?VirtualMachine'
},
{
test: require.resolve('./src/extensions/scratch3_video_sensing/debug.js'),
loader: 'expose-loader?Scratch3VideoSensingDebug'
},
{
test: require.resolve('stats.js/build/stats.min.js'),
loader: 'script-loader'
},
{
test: require.resolve('scratch-blocks/dist/vertical.js'),
loader: 'expose-loader?Blockly'
},
{
test: require.resolve('scratch-audio/src/index.js'),
loader: 'expose-loader?AudioEngine'
},
{
test: require.resolve('scratch-storage/src/index.js'),
loader: 'expose-loader?ScratchStorage'
},
{
test: require.resolve('scratch-render/src/index.js'),
loader: 'expose-loader?ScratchRender'
}
])
},
performance: {
hints: false
},
plugins: base.plugins.concat([
new CopyWebpackPlugin([{
from: 'node_modules/scratch-blocks/media',
to: 'media'
}, {
from: 'node_modules/scratch-storage/dist/web'
}, {
from: 'node_modules/scratch-render/dist/web'
}, {
from: 'node_modules/@turbowarp/scratch-svg-renderer/dist/web'
}, {
from: 'src/playground'
}])
])
})
];