solana/web3.js/rollup.config.js

111 lines
2.7 KiB
JavaScript
Raw Normal View History

import babel from 'rollup-plugin-babel';
2018-08-22 21:43:32 -07:00
import builtins from 'rollup-plugin-node-builtins';
import commonjs from 'rollup-plugin-commonjs';
2018-08-22 21:43:32 -07:00
import globals from 'rollup-plugin-node-globals';
import json from 'rollup-plugin-json';
2018-08-22 17:03:50 -07:00
import nodeResolve from 'rollup-plugin-node-resolve';
import replace from 'rollup-plugin-replace';
import uglify from 'rollup-plugin-uglify';
const env = process.env.NODE_ENV;
2018-08-22 21:43:32 -07:00
function generateConfig(configType) {
const config = {
input: 'src/index.js',
plugins: [
2018-08-23 10:52:48 -07:00
json(),
2018-08-22 21:43:32 -07:00
babel({
exclude: '**/node_modules/**',
runtimeHelpers: true,
}),
replace({
'process.env.NODE_ENV': JSON.stringify(env),
}),
commonjs(),
],
};
2018-08-22 21:43:32 -07:00
if (env === 'production') {
config.plugins.push(
uglify({
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
warnings: false,
},
}),
);
}
2018-08-22 21:43:32 -07:00
switch (configType) {
case 'browser':
config.output = [
{
file: 'lib/index.iife.js',
format: 'iife',
name: 'solanaWeb3',
},
2018-08-22 21:43:32 -07:00
];
config.plugins.push(builtins());
config.plugins.push(globals());
2018-08-23 19:50:37 -07:00
config.plugins.push(nodeResolve({
browser: true,
}));
2018-08-22 21:43:32 -07:00
break;
case 'node':
config.output = [
{
file: 'lib/index.cjs.js',
format: 'cjs',
},
{
file: 'lib/index.esm.js',
format: 'es',
},
];
2018-08-24 08:22:54 -07:00
// Quash 'Unresolved dependencies' complaints for modules listed in the
// package.json "dependencies" section. Unfortunately this list is manually
// maintained.
config.external = [
'assert',
2018-10-26 21:37:39 -07:00
'babel-runtime/core-js/get-iterator',
'babel-runtime/core-js/json/stringify',
'babel-runtime/core-js/object/assign',
'babel-runtime/core-js/object/get-prototype-of',
'babel-runtime/core-js/object/keys',
2018-08-24 08:22:54 -07:00
'babel-runtime/core-js/promise',
'babel-runtime/helpers/asyncToGenerator',
'babel-runtime/helpers/classCallCheck',
'babel-runtime/helpers/createClass',
2018-10-26 21:37:39 -07:00
'babel-runtime/helpers/get',
'babel-runtime/helpers/inherits',
'babel-runtime/helpers/possibleConstructorReturn',
2018-08-24 08:22:54 -07:00
'babel-runtime/helpers/toConsumableArray',
'babel-runtime/helpers/typeof',
'babel-runtime/regenerator',
2018-10-26 21:37:39 -07:00
'bn.js',
2018-08-24 08:22:54 -07:00
'bs58',
2018-10-26 21:37:39 -07:00
'buffer-layout',
'elfy',
2018-08-24 08:22:54 -07:00
'jayson/lib/client/browser',
'node-fetch',
2018-10-26 21:37:39 -07:00
'rpc-websockets',
2018-08-24 08:22:54 -07:00
'superstruct',
'tweetnacl',
2018-10-26 21:37:39 -07:00
'url',
2018-08-24 08:22:54 -07:00
];
2018-08-22 21:43:32 -07:00
break;
default:
throw new Error(`Unknown configType: ${configType}`);
}
return config;
}
2018-08-22 21:43:32 -07:00
export default [
generateConfig('node'),
generateConfig('browser'),
];