2018-01-04 11:00:45 -08:00
|
|
|
const defaultsdeep = require('lodash.defaultsdeep');
|
2017-09-05 11:57:48 -04:00
|
|
|
const path = require('path');
|
|
|
|
const webpack = require('webpack');
|
2018-04-25 16:08:35 -04:00
|
|
|
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
2017-09-05 11:57:48 -04:00
|
|
|
|
2018-01-04 11:00:45 -08:00
|
|
|
const makeExport = function (targets, settings) {
|
|
|
|
const base = {
|
2018-04-25 16:08:35 -04:00
|
|
|
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
|
2018-01-04 11:00:45 -08:00
|
|
|
devtool: 'cheap-module-source-map',
|
|
|
|
module: {
|
|
|
|
rules: [{
|
|
|
|
include: path.resolve('src'),
|
|
|
|
test: /\.js$/,
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
presets: [['env', {targets}]]
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
entry: {
|
2018-04-22 21:34:07 -04:00
|
|
|
'scratch-svg-renderer': './src/index.js'
|
2018-01-04 11:00:45 -08:00
|
|
|
},
|
2018-04-25 16:08:35 -04:00
|
|
|
optimization: {
|
|
|
|
minimize: process.env.NODE_ENV === 'production' && /dist[\//]web/.test(settings.output.path)
|
|
|
|
}
|
2018-01-04 11:00:45 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
return defaultsdeep(base, settings);
|
2017-09-05 11:57:48 -04:00
|
|
|
};
|
2018-01-04 11:00:45 -08:00
|
|
|
|
|
|
|
module.exports = [
|
|
|
|
makeExport({browsers: ['last 3 versions', 'Safari >= 8', 'iOS >= 8']}, {
|
|
|
|
output: {
|
|
|
|
library: 'ScratchSVGRenderer',
|
|
|
|
libraryTarget: 'umd',
|
|
|
|
path: path.resolve('dist', 'web'),
|
|
|
|
filename: '[name].js'
|
|
|
|
}
|
|
|
|
}),
|
2018-01-04 11:50:33 -08:00
|
|
|
// For testing only: many features will fail outside a browser
|
2018-01-23 21:37:02 -08:00
|
|
|
makeExport({node: true, uglify: true}, {
|
2018-01-04 11:00:45 -08:00
|
|
|
output: {
|
|
|
|
library: 'ScratchSVGRenderer',
|
|
|
|
libraryTarget: 'commonjs2',
|
|
|
|
path: path.resolve('dist', 'node'),
|
|
|
|
filename: '[name].js'
|
2018-04-25 16:08:35 -04:00
|
|
|
},
|
|
|
|
performance: {
|
|
|
|
hints: false
|
2018-01-04 11:00:45 -08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
];
|