scratch-vm/webpack.config.js

148 lines
4.4 KiB
JavaScript
Raw Normal View History

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
const base = {
2018-05-03 18:56:10 -04:00
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'
},
2017-04-17 19:55:34 -04:00
module: {
rules: [{
test: /\.js$/,
loader: 'babel-loader',
include: path.resolve(__dirname, 'src'),
query: {
presets: [['@babel/preset-env', {targets: {browsers: ['last 3 versions', 'Safari >= 8', 'iOS >= 8']}}]]
2017-04-17 19:55:34 -04: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
};
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: {
2017-04-17 19:55:34 -04:00
rules: base.module.rules.concat([
{
test: require.resolve('./src/index.js'),
loader: 'expose-loader?VirtualMachine'
}
2017-04-17 19:55:34 -04:00
])
}
}),
// 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,
'jszip': true,
'minilog': true,
'nets': true,
'scratch-parser': true,
'socket.io-client': true,
'text-encoding': true
2018-02-14 17:55:11 -05:00
}
}),
// Playground
defaultsDeep({}, base, {
target: 'web',
entry: {
2019-01-22 17:42:34 -05:00
'benchmark': './src/playground/benchmark',
'video-sensing-extension-debug': './src/extensions/scratch3_video_sensing/debug'
},
output: {
2017-12-12 12:17:33 -05:00
path: path.resolve(__dirname, 'playground'),
filename: '[name].js'
},
module: {
2017-04-17 19:55:34 -04:00
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'),
2017-12-12 12:17:33 -05:00
loader: 'expose-loader?ScratchStorage'
},
{
test: require.resolve('scratch-render/src/index.js'),
loader: 'expose-loader?ScratchRender'
}
])
},
2018-05-03 18:56:10 -04:00
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/scratch-svg-renderer/dist/web'
}, {
2017-12-12 12:17:33 -05:00
from: 'src/playground'
}])
])
})
];