1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-11-29 07:16:25 +01:00
js-bigchaindb-driver/webpack.config.js

112 lines
2.7 KiB
JavaScript
Raw Normal View History

2017-04-26 15:58:19 +02:00
/* eslint-disable strict, no-console, object-shorthand */
2017-06-12 16:57:29 +02:00
'use strict'
2017-04-26 15:58:19 +02:00
2017-06-12 16:57:29 +02:00
const path = require('path')
2017-04-26 15:58:19 +02:00
2017-06-12 16:57:29 +02:00
const webpack = require('webpack')
2017-04-26 15:58:19 +02:00
2017-06-12 16:57:29 +02:00
const PRODUCTION = process.env.NODE_ENV === 'production'
2017-04-26 15:58:19 +02:00
const PATHS = {
ENTRY: path.resolve(__dirname, './src/index.js'),
2017-06-16 14:21:33 +02:00
BUNDLE: path.resolve(__dirname, 'dist/browser'),
2017-04-26 15:58:19 +02:00
NODE_MODULES: path.resolve(__dirname, 'node_modules'),
2017-06-12 16:57:29 +02:00
}
2017-04-26 15:58:19 +02:00
2017-06-21 17:39:19 +02:00
const OUTPUTS = [
{
2017-06-22 10:53:22 +02:00
filename: PRODUCTION ? 'bigchaindb-driver.window.min.js' : 'bigchaindb-driver.window.js',
2017-06-21 17:39:19 +02:00
library: 'BigchainDB',
libraryTarget: 'window',
path: PATHS.BUNDLE,
},
{
2017-06-22 10:53:22 +02:00
filename: PRODUCTION ? 'bigchaindb-driver.umd.min.js' : 'bigchaindb-driver.umd.js',
2017-06-21 17:39:19 +02:00
library: 'bigchaindb-driver',
libraryTarget: 'umd',
path: PATHS.BUNDLE,
},
{
2017-06-22 10:53:22 +02:00
filename: PRODUCTION ? 'bigchaindb-driver.cjs.min.js' : 'bigchaindb-driver.cjs.js',
2017-06-21 17:39:19 +02:00
library: 'bigchaindb-driver',
libraryTarget: 'commonjs',
path: PATHS.BUNDLE,
},
{
2017-06-22 10:53:22 +02:00
filename: PRODUCTION ? 'bigchaindb-driver.cjs2.min.js' : 'bigchaindb-driver.cjs2.js',
2017-06-21 17:39:19 +02:00
library: 'bigchaindb-driver',
libraryTarget: 'commonjs2',
path: PATHS.BUNDLE,
},
{
2017-06-22 10:53:22 +02:00
filename: PRODUCTION ? 'bigchaindb-driver.amd.min.js' : 'bigchaindb-driver.amd.js',
2017-06-21 17:39:19 +02:00
library: 'bigchaindb-driver',
libraryTarget: 'amd',
path: PATHS.BUNDLE,
}
]
2017-04-26 15:58:19 +02:00
/** PLUGINS **/
const PLUGINS = [
new webpack.NoEmitOnErrorsPlugin(),
2017-06-12 16:57:29 +02:00
]
2017-04-26 15:58:19 +02:00
const PROD_PLUGINS = [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
},
output: {
comments: false,
},
sourceMap: true,
}),
new webpack.LoaderOptionsPlugin({
debug: false,
minimize: true,
}),
2017-06-12 16:57:29 +02:00
]
2017-04-26 15:58:19 +02:00
if (PRODUCTION) {
2017-06-12 16:57:29 +02:00
PLUGINS.push(...PROD_PLUGINS)
2017-04-26 15:58:19 +02:00
}
2017-06-21 17:39:19 +02:00
const configBoilerplate = {
2017-04-26 15:58:19 +02:00
entry: [PATHS.ENTRY],
devtool: PRODUCTION ? '#source-map' : '#inline-source-map',
resolve: {
extensions: ['.js'],
modules: ['node_modules'], // Don't use absolute path here to allow recursive matching
},
plugins: PLUGINS,
module: {
rules: [
{
test: /\.js$/,
exclude: [PATHS.NODE_MODULES],
use: [{
loader: 'babel-loader',
options: {
cacheDirectory: true,
},
}],
},
],
},
2017-06-12 16:57:29 +02:00
}
2017-04-26 15:58:19 +02:00
2017-06-21 17:39:19 +02:00
/** EXPORTED WEBPACK CONFIG **/
const config = OUTPUTS.map(output => {
const configCopy = Object.assign({}, configBoilerplate)
configCopy.output = output
return configCopy
})
2017-06-12 16:57:29 +02:00
module.exports = config