mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-25 07:22:33 -05:00
7fb7f0dc7b
When asked to load an extension, the Extension Manager starts up a new Worker. That worker runs the message dispatch system as well as an instance of the new `ExtensionWorker` class, which will load the desired extension and register it with the extension system. Extensions, placed in `./src/extensions/*.js`, are now processed by Webpack as separate entry points and packed into an `extensions` subdirectory in the output. Still to do: query an extension's information, including the blocks it provides, and register that information with the VM, GUI, etc.
139 lines
4.2 KiB
JavaScript
139 lines
4.2 KiB
JavaScript
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
const defaultsDeep = require('lodash.defaultsdeep');
|
|
const glob = require('glob');
|
|
const path = require('path');
|
|
const webpack = require('webpack');
|
|
|
|
const extensionEntries = glob.sync('./src/extensions/*.js').reduce((bag, extensionPath) => {
|
|
const nameWithoutExtension = path.basename(extensionPath).replace(/\.[^/.]+$/, '');
|
|
bag[`extensions/${nameWithoutExtension}`] = extensionPath;
|
|
return bag;
|
|
}, {});
|
|
|
|
const base = {
|
|
devServer: {
|
|
contentBase: false,
|
|
host: '0.0.0.0',
|
|
port: process.env.PORT || 8073
|
|
},
|
|
devtool: 'cheap-module-source-map',
|
|
module: {
|
|
rules: [{
|
|
test: /\.js$/,
|
|
loader: 'babel-loader',
|
|
include: path.resolve(__dirname, 'src'),
|
|
query: {
|
|
presets: ['es2015']
|
|
}
|
|
}]
|
|
},
|
|
plugins: [
|
|
new webpack.optimize.UglifyJsPlugin({
|
|
include: /\.min\.js$/,
|
|
minimize: true
|
|
})
|
|
]
|
|
};
|
|
|
|
module.exports = [
|
|
// Web-compatible
|
|
defaultsDeep({}, base, {
|
|
target: 'web',
|
|
entry: defaultsDeep({}, extensionEntries, {
|
|
'scratch-vm': './src/index.js',
|
|
'scratch-vm.min': './src/index.js'
|
|
}),
|
|
output: {
|
|
path: path.resolve(__dirname, 'dist/web'),
|
|
filename: '[name].js'
|
|
},
|
|
module: {
|
|
rules: base.module.rules.concat([
|
|
{
|
|
test: require.resolve('./src/index.js'),
|
|
loader: 'expose-loader?VirtualMachine'
|
|
}
|
|
])
|
|
}
|
|
}),
|
|
// Node-compatible
|
|
defaultsDeep({}, base, {
|
|
target: 'node',
|
|
entry: defaultsDeep({}, extensionEntries, {
|
|
'scratch-vm': './src/index.js'
|
|
}),
|
|
output: {
|
|
library: 'VirtualMachine',
|
|
libraryTarget: 'commonjs2',
|
|
path: path.resolve(__dirname, 'dist/node'),
|
|
filename: '[name].js'
|
|
}
|
|
}),
|
|
// Playground
|
|
defaultsDeep({}, base, {
|
|
target: 'web',
|
|
entry: defaultsDeep({}, extensionEntries, {
|
|
'scratch-vm': './src/index.js',
|
|
'vendor': [
|
|
// FPS counter
|
|
'stats.js/build/stats.min.js',
|
|
// Syntax highlighter
|
|
'highlightjs/highlight.pack.min.js',
|
|
// Scratch Blocks
|
|
'scratch-blocks/dist/vertical.js',
|
|
// Audio
|
|
'scratch-audio',
|
|
// Renderer
|
|
'scratch-render',
|
|
// Storage
|
|
'scratch-storage'
|
|
]
|
|
}),
|
|
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('stats.js/build/stats.min.js'),
|
|
loader: 'script-loader'
|
|
},
|
|
{
|
|
test: require.resolve('highlightjs/highlight.pack.min.js'),
|
|
loader: 'script-loader'
|
|
},
|
|
{
|
|
test: require.resolve('scratch-blocks/dist/vertical.js'),
|
|
loader: 'expose-loader?Blockly'
|
|
},
|
|
{
|
|
test: require.resolve('scratch-audio'),
|
|
loader: 'expose-loader?AudioEngine'
|
|
},
|
|
{
|
|
test: require.resolve('scratch-render'),
|
|
loader: 'expose-loader?RenderWebGL'
|
|
},
|
|
{
|
|
test: require.resolve('scratch-storage'),
|
|
loader: 'expose-loader?Scratch.Storage'
|
|
}
|
|
])
|
|
},
|
|
plugins: base.plugins.concat([
|
|
new CopyWebpackPlugin([{
|
|
from: 'node_modules/scratch-blocks/media',
|
|
to: 'media'
|
|
}, {
|
|
from: 'node_modules/highlightjs/styles/zenburn.css'
|
|
}, {
|
|
from: 'src/playground'
|
|
}])
|
|
])
|
|
})
|
|
];
|