2016-10-21 18:27:47 -07:00
|
|
|
const path = require('path');
|
2018-05-07 13:32:29 -04:00
|
|
|
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
2016-10-21 18:27:47 -07:00
|
|
|
|
|
|
|
const base = {
|
2018-05-07 13:32:29 -04:00
|
|
|
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
|
2017-04-11 11:36:14 -04:00
|
|
|
devtool: 'cheap-module-source-map',
|
2016-10-21 18:27:47 -07:00
|
|
|
module: {
|
2017-02-03 12:18:05 -08:00
|
|
|
rules: [
|
2016-10-21 18:27:47 -07:00
|
|
|
{
|
|
|
|
include: [
|
2017-09-13 10:40:08 -07:00
|
|
|
path.resolve('src')
|
2016-10-21 18:27:47 -07:00
|
|
|
],
|
|
|
|
test: /\.js$/,
|
|
|
|
loader: 'babel-loader',
|
2017-02-03 12:18:05 -08:00
|
|
|
options: {
|
2023-03-08 11:23:10 -08:00
|
|
|
plugins: [
|
|
|
|
'@babel/plugin-transform-runtime'
|
|
|
|
],
|
2018-10-24 10:43:46 +01:00
|
|
|
presets: [
|
|
|
|
['@babel/preset-env', {targets: {browsers: ['last 3 versions', 'Safari >= 8', 'iOS >= 8']}}]
|
2023-03-08 11:23:10 -08:00
|
|
|
],
|
|
|
|
// Consider a file a "module" if import/export statements are present, or else consider it a
|
|
|
|
// "script". Fixes "Cannot assign to read only property 'exports'" when using
|
|
|
|
// @babel/plugin-transform-runtime with CommonJS files.
|
|
|
|
sourceType: 'unambiguous'
|
2016-10-21 18:27:47 -07:00
|
|
|
}
|
2023-05-01 14:18:09 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|svg|wav)$/,
|
|
|
|
loader: 'arraybuffer-loader'
|
2016-10-21 18:27:47 -07:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2018-05-07 13:32:29 -04:00
|
|
|
optimization: {
|
|
|
|
minimizer: [
|
|
|
|
new UglifyJsPlugin({
|
|
|
|
include: /\.min\.js$/,
|
|
|
|
sourceMap: true
|
|
|
|
})
|
|
|
|
]
|
|
|
|
},
|
|
|
|
plugins: []
|
2016-10-21 18:27:47 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = [
|
2017-09-13 10:40:08 -07:00
|
|
|
// Web-compatible
|
2016-10-21 18:27:47 -07:00
|
|
|
Object.assign({}, base, {
|
2016-12-06 16:23:11 -08:00
|
|
|
target: 'web',
|
2016-10-21 18:27:47 -07:00
|
|
|
entry: {
|
2017-09-26 00:39:03 -04:00
|
|
|
'scratch-storage': './src/index.js',
|
|
|
|
'scratch-storage.min': './src/index.js'
|
2016-10-21 18:27:47 -07:00
|
|
|
},
|
2017-09-08 15:08:26 +08:00
|
|
|
output: {
|
|
|
|
library: 'ScratchStorage',
|
2017-09-13 10:40:08 -07:00
|
|
|
libraryTarget: 'umd',
|
|
|
|
path: path.resolve('dist', 'web'),
|
|
|
|
filename: '[name].js'
|
2017-09-08 15:08:26 +08:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
2017-09-13 10:40:08 -07:00
|
|
|
// Node-compatible
|
2016-10-21 18:27:47 -07:00
|
|
|
Object.assign({}, base, {
|
2016-12-06 16:23:11 -08:00
|
|
|
target: 'node',
|
2016-10-21 18:27:47 -07:00
|
|
|
entry: {
|
|
|
|
'scratch-storage': './src/index.js'
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
library: 'ScratchStorage',
|
|
|
|
libraryTarget: 'commonjs2',
|
2017-09-13 10:40:08 -07:00
|
|
|
path: path.resolve('dist', 'node'),
|
|
|
|
filename: '[name].js'
|
2018-04-30 14:35:31 -04:00
|
|
|
},
|
|
|
|
externals: {
|
|
|
|
'base64-js': true,
|
|
|
|
'js-md5': true,
|
|
|
|
'localforage': true,
|
|
|
|
'text-encoding': true
|
2023-03-08 07:25:42 -08:00
|
|
|
}
|
2016-10-21 18:27:47 -07:00
|
|
|
})
|
|
|
|
];
|