2017-04-20 19:17:05 -04:00
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
|
|
const defaultsDeep = require('lodash.defaultsdeep');
|
|
|
|
const path = require('path');
|
2018-05-03 18:56:10 -04:00
|
|
|
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
2016-04-18 17:20:30 -04:00
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
const base = {
|
2018-05-03 18:56:10 -04:00
|
|
|
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
|
2016-09-26 10:02:24 -04:00
|
|
|
devServer: {
|
2017-02-10 17:21:37 -05:00
|
|
|
contentBase: false,
|
2016-11-21 14:25:08 -05:00
|
|
|
host: '0.0.0.0',
|
|
|
|
port: process.env.PORT || 8073
|
2016-09-26 10:02:24 -04:00
|
|
|
},
|
2017-04-11 11:36:59 -04:00
|
|
|
devtool: 'cheap-module-source-map',
|
2017-11-27 23:00:03 -05:00
|
|
|
output: {
|
|
|
|
library: 'VirtualMachine',
|
|
|
|
filename: '[name].js'
|
|
|
|
},
|
2017-04-17 19:55:34 -04:00
|
|
|
module: {
|
|
|
|
rules: [{
|
|
|
|
test: /\.js$/,
|
|
|
|
loader: 'babel-loader',
|
|
|
|
include: path.resolve(__dirname, 'src'),
|
|
|
|
query: {
|
2018-10-17 07:14:49 -04:00
|
|
|
presets: [['@babel/preset-env', {targets: {browsers: ['last 3 versions', 'Safari >= 8', 'iOS >= 8']}}]]
|
2017-04-17 19:55:34 -04:00
|
|
|
}
|
2018-02-14 17:53:05 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.mp3$/,
|
|
|
|
loader: 'file-loader'
|
2017-04-17 19:55:34 -04:00
|
|
|
}]
|
|
|
|
},
|
2018-05-03 18:56:10 -04:00
|
|
|
optimization: {
|
|
|
|
minimizer: [
|
|
|
|
new UglifyJsPlugin({
|
|
|
|
include: /\.min\.js$/
|
|
|
|
})
|
|
|
|
]
|
|
|
|
},
|
|
|
|
plugins: []
|
2016-04-18 17:20:30 -04:00
|
|
|
};
|
2016-09-20 15:52:35 -04:00
|
|
|
|
2016-09-24 18:11:01 -04:00
|
|
|
module.exports = [
|
2017-01-13 16:34:26 -05:00
|
|
|
// Web-compatible
|
2016-09-24 18:11:01 -04:00
|
|
|
defaultsDeep({}, base, {
|
2017-01-13 16:34:26 -05:00
|
|
|
target: 'web',
|
2016-09-24 18:11:01 -04:00
|
|
|
entry: {
|
2017-01-13 16:34:26 -05:00
|
|
|
'scratch-vm': './src/index.js',
|
|
|
|
'scratch-vm.min': './src/index.js'
|
2016-09-24 18:11:01 -04:00
|
|
|
},
|
|
|
|
output: {
|
2017-11-27 23:00:03 -05:00
|
|
|
libraryTarget: 'umd',
|
|
|
|
path: path.resolve('dist', 'web')
|
2016-09-24 18:11:01 -04:00
|
|
|
},
|
|
|
|
module: {
|
2017-04-17 19:55:34 -04:00
|
|
|
rules: base.module.rules.concat([
|
2016-09-24 18:11:01 -04:00
|
|
|
{
|
|
|
|
test: require.resolve('./src/index.js'),
|
2017-02-01 15:30:27 -05:00
|
|
|
loader: 'expose-loader?VirtualMachine'
|
2016-09-24 18:11:01 -04:00
|
|
|
}
|
2017-04-17 19:55:34 -04:00
|
|
|
])
|
2016-09-24 18:11:01 -04:00
|
|
|
}
|
|
|
|
}),
|
2017-01-13 16:34:26 -05:00
|
|
|
// Node-compatible
|
2016-09-24 18:11:01 -04:00
|
|
|
defaultsDeep({}, base, {
|
2017-01-13 16:34:26 -05:00
|
|
|
target: 'node',
|
2016-09-24 18:11:01 -04:00
|
|
|
entry: {
|
2017-01-13 16:34:26 -05:00
|
|
|
'scratch-vm': './src/index.js'
|
2016-09-24 18:11:01 -04:00
|
|
|
},
|
|
|
|
output: {
|
|
|
|
libraryTarget: 'commonjs2',
|
2017-11-27 23:00:03 -05:00
|
|
|
path: path.resolve('dist', 'node')
|
2018-04-30 11:53:01 -04:00
|
|
|
},
|
|
|
|
externals: {
|
|
|
|
'decode-html': true,
|
|
|
|
'format-message': true,
|
|
|
|
'htmlparser2': true,
|
|
|
|
'immutable': true,
|
|
|
|
'jszip': true,
|
|
|
|
'minilog': true,
|
|
|
|
'nets': true,
|
|
|
|
'scratch-parser': true,
|
|
|
|
'socket.io-client': true,
|
|
|
|
'text-encoding': true
|
2018-02-14 17:55:11 -05:00
|
|
|
}
|
2016-09-24 18:11:01 -04:00
|
|
|
}),
|
|
|
|
// Playground
|
|
|
|
defaultsDeep({}, base, {
|
2017-01-13 16:34:26 -05:00
|
|
|
target: 'web',
|
2016-09-24 18:11:01 -04:00
|
|
|
entry: {
|
2019-01-22 17:42:34 -05:00
|
|
|
'benchmark': './src/playground/benchmark',
|
2018-03-30 14:54:58 -04:00
|
|
|
'video-sensing-extension-debug': './src/extensions/scratch3_video_sensing/debug'
|
2016-09-24 18:11:01 -04:00
|
|
|
},
|
|
|
|
output: {
|
2017-12-12 12:17:33 -05:00
|
|
|
path: path.resolve(__dirname, 'playground'),
|
|
|
|
filename: '[name].js'
|
2016-09-24 18:11:01 -04:00
|
|
|
},
|
|
|
|
module: {
|
2017-04-17 19:55:34 -04:00
|
|
|
rules: base.module.rules.concat([
|
2016-09-24 18:11:01 -04:00
|
|
|
{
|
|
|
|
test: require.resolve('./src/index.js'),
|
2017-02-01 15:30:27 -05:00
|
|
|
loader: 'expose-loader?VirtualMachine'
|
2016-09-24 18:11:01 -04:00
|
|
|
},
|
2018-03-22 11:52:23 -04:00
|
|
|
{
|
|
|
|
test: require.resolve('./src/extensions/scratch3_video_sensing/debug.js'),
|
2018-03-30 14:54:58 -04:00
|
|
|
loader: 'expose-loader?Scratch3VideoSensingDebug'
|
2018-03-22 11:52:23 -04:00
|
|
|
},
|
2016-09-24 18:11:01 -04:00
|
|
|
{
|
|
|
|
test: require.resolve('stats.js/build/stats.min.js'),
|
2017-02-01 15:30:27 -05:00
|
|
|
loader: 'script-loader'
|
2016-09-24 18:11:01 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: require.resolve('scratch-blocks/dist/vertical.js'),
|
2017-02-01 15:30:27 -05:00
|
|
|
loader: 'expose-loader?Blockly'
|
2016-09-24 18:11:01 -04:00
|
|
|
},
|
2017-01-27 13:44:48 -05:00
|
|
|
{
|
2018-06-01 13:38:18 -04:00
|
|
|
test: require.resolve('scratch-audio/src/index.js'),
|
2017-01-27 13:44:48 -05:00
|
|
|
loader: 'expose-loader?AudioEngine'
|
|
|
|
},
|
2016-09-24 18:11:01 -04:00
|
|
|
{
|
2018-06-01 13:38:18 -04:00
|
|
|
test: require.resolve('scratch-storage/src/index.js'),
|
2017-12-12 12:17:33 -05:00
|
|
|
loader: 'expose-loader?ScratchStorage'
|
2017-11-09 18:35:12 -05:00
|
|
|
},
|
|
|
|
{
|
2018-06-01 13:38:18 -04:00
|
|
|
test: require.resolve('scratch-render/src/index.js'),
|
2018-01-29 17:04:19 -05:00
|
|
|
loader: 'expose-loader?ScratchRender'
|
2017-11-09 18:35:12 -05:00
|
|
|
}
|
|
|
|
])
|
|
|
|
},
|
2018-05-03 18:56:10 -04:00
|
|
|
performance: {
|
|
|
|
hints: false
|
|
|
|
},
|
2017-11-09 18:35:12 -05:00
|
|
|
plugins: base.plugins.concat([
|
|
|
|
new CopyWebpackPlugin([{
|
|
|
|
from: 'node_modules/scratch-blocks/media',
|
|
|
|
to: 'media'
|
|
|
|
}, {
|
|
|
|
from: 'node_modules/scratch-storage/dist/web'
|
2018-01-29 17:04:19 -05:00
|
|
|
}, {
|
|
|
|
from: 'node_modules/scratch-render/dist/web'
|
2018-08-08 14:36:38 -04:00
|
|
|
}, {
|
|
|
|
from: 'node_modules/scratch-svg-renderer/dist/web'
|
2017-11-09 18:35:12 -05:00
|
|
|
}, {
|
2017-12-12 12:17:33 -05:00
|
|
|
from: 'src/playground'
|
2017-11-09 18:35:12 -05:00
|
|
|
}])
|
|
|
|
])
|
2016-09-24 18:11:01 -04:00
|
|
|
})
|
|
|
|
];
|