scratch-storage/webpack.config.js

81 lines
2.3 KiB
JavaScript
Raw Normal View History

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',
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: [
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: {
plugins: [
'@babel/plugin-transform-runtime'
],
presets: [
['@babel/preset-env', {targets: {browsers: ['last 3 versions', 'Safari >= 8', 'iOS >= 8']}}]
],
// 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
}
},
{
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 = [
// Web-compatible
2016-10-21 18:27:47 -07:00
Object.assign({}, base, {
target: 'web',
2016-10-21 18:27:47 -07:00
entry: {
'scratch-storage': './src/index.js',
'scratch-storage.min': './src/index.js'
2016-10-21 18:27:47 -07:00
},
output: {
library: 'ScratchStorage',
libraryTarget: 'umd',
path: path.resolve('dist', 'web'),
filename: '[name].js'
}
}),
// Node-compatible
2016-10-21 18:27:47 -07:00
Object.assign({}, base, {
target: 'node',
2016-10-21 18:27:47 -07:00
entry: {
'scratch-storage': './src/index.js'
},
output: {
library: 'ScratchStorage',
libraryTarget: 'commonjs2',
path: path.resolve('dist', 'node'),
filename: '[name].js'
},
externals: {
'base64-js': true,
'js-md5': true,
'localforage': true,
'text-encoding': true
}
2016-10-21 18:27:47 -07:00
})
];