scratch-vm/webpack.config.js

133 lines
3.8 KiB
JavaScript
Raw Normal View History

const CopyWebpackPlugin = require('copy-webpack-plugin');
const defaultsDeep = require('lodash.defaultsdeep');
const path = require('path');
const webpack = require('webpack');
2016-04-18 17:20:30 -04:00
const base = {
devServer: {
contentBase: false,
host: '0.0.0.0',
port: process.env.PORT || 8073
},
devtool: 'cheap-module-source-map',
2017-04-17 19:55:34 -04:00
module: {
rules: [{
test: /\.js$/,
loader: 'babel-loader',
include: path.resolve(__dirname, 'src'),
query: {
presets: ['es2015']
}
}]
},
2016-04-18 17:20:30 -04:00
plugins: [
new webpack.optimize.UglifyJsPlugin({
include: /\.min\.js$/,
minimize: true
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: {
path: path.resolve(__dirname, 'dist/web'),
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'
}
2017-04-17 19:55:34 -04:00
])
}
}),
// Node-compatible
defaultsDeep({}, base, {
target: 'node',
entry: {
'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: {
'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
2017-01-06 11:49:25 -05:00
'scratch-render',
// Storage
'scratch-storage'
]
},
output: {
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('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'
2017-01-06 11:49:25 -05:00
},
{
test: require.resolve('scratch-storage'),
loader: 'expose-loader?Scratch.Storage'
}
2017-04-17 19:55:34 -04:00
])
},
plugins: base.plugins.concat([
new CopyWebpackPlugin([{
from: 'node_modules/scratch-blocks/media',
to: 'media'
}, {
from: 'node_modules/highlightjs/styles/zenburn.css'
}, {
from: 'src/playground'
}])
])
})
];