mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
4ceeebb257
Use src/index.js as the entry by default in tools building scratch-vm into a larger package. This saves file space by excluding extra webpack boilerplate and may allow for deeper optimizations. Depend on script dependencies for downstream webpack. For another package to build in scratch-vm's dependencies without them already being built into a consumed webpack build they need to be listed as dependencies. This can benefit large projects that reuse the same dependencies multiple times. Node will still use the main entry point and its webpack build leaves the dependencies as external references so it may reuse common modules in Node as well as in a build a browser environment.
162 lines
4.8 KiB
JavaScript
162 lines
4.8 KiB
JavaScript
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
const defaultsDeep = require('lodash.defaultsdeep');
|
|
const path = require('path');
|
|
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
|
|
|
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: [['env', {targets: {browsers: ['last 3 versions', 'Safari >= 8', 'iOS >= 8']}}]]
|
|
}
|
|
},
|
|
{
|
|
test: /\.mp3$/,
|
|
loader: 'file-loader'
|
|
}]
|
|
},
|
|
optimization: {
|
|
minimizer: [
|
|
new UglifyJsPlugin({
|
|
include: /\.min\.js$/
|
|
})
|
|
]
|
|
},
|
|
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,
|
|
'escape-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
|
|
}
|
|
}),
|
|
// Playground
|
|
defaultsDeep({}, base, {
|
|
target: 'web',
|
|
entry: {
|
|
'scratch-vm': './src/index.js',
|
|
'vendor': [
|
|
// FPS counter
|
|
'stats.js/build/stats.min.js',
|
|
// Scratch Blocks
|
|
'scratch-blocks/dist/vertical.js',
|
|
// Audio
|
|
'scratch-audio',
|
|
// Storage
|
|
'scratch-storage',
|
|
// Renderer
|
|
'scratch-render'
|
|
],
|
|
'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('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-storage'),
|
|
loader: 'expose-loader?ScratchStorage'
|
|
},
|
|
{
|
|
test: require.resolve('scratch-render'),
|
|
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: 'src/playground'
|
|
}])
|
|
])
|
|
})
|
|
];
|