solana/web3.js/rollup.config.js

113 lines
3.0 KiB
JavaScript
Raw Normal View History

2018-11-04 11:41:21 -08:00
import babel from 'rollup-plugin-babel';
import builtins from 'rollup-plugin-node-builtins';
import commonjs from 'rollup-plugin-commonjs';
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';
2018-11-04 11:41:21 -08:00
import replace from 'rollup-plugin-replace';
import {terser} from 'rollup-plugin-terser';
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
switch (configType) {
2018-11-04 11:41:21 -08:00
case 'browser':
config.output = [
{
file: 'lib/index.iife.js',
format: 'iife',
name: 'solanaWeb3',
2018-12-02 10:17:15 -08:00
sourcemap: true,
2018-11-04 11:41:21 -08:00
},
];
config.plugins.push(builtins());
config.plugins.push(globals());
config.plugins.push(
nodeResolve({
browser: true,
}),
);
if (env === 'production') {
config.plugins.push(
terser({
mangle: false,
compress: false,
sourcemap: true,
}),
);
}
2018-11-04 11:41:21 -08:00
break;
case 'node':
config.output = [
{
file: 'lib/index.cjs.js',
format: 'cjs',
2018-12-02 10:17:15 -08:00
sourcemap: true,
2018-11-04 11:41:21 -08:00
},
{
file: 'lib/index.esm.js',
format: 'es',
2018-12-02 10:17:15 -08:00
sourcemap: true,
2018-11-04 11:41:21 -08:00
},
];
2018-08-24 08:22:54 -07:00
2018-11-04 11:41:21 -08:00
// Quash 'Unresolved dependencies' complaints for modules listed in the
// package.json "dependencies" section. Unfortunately this list is manually
// maintained.
config.external = [
'assert',
'@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',
'@babel/runtime/core-js/promise',
'@babel/runtime/helpers/asyncToGenerator',
'@babel/runtime/helpers/classCallCheck',
'@babel/runtime/helpers/createClass',
'@babel/runtime/helpers/defineProperty',
'@babel/runtime/helpers/get',
'@babel/runtime/helpers/getPrototypeOf',
'@babel/runtime/helpers/inherits',
'@babel/runtime/helpers/possibleConstructorReturn',
'@babel/runtime/helpers/slicedToArray',
'@babel/runtime/helpers/toConsumableArray',
'@babel/runtime/helpers/typeof',
'@babel/runtime/regenerator',
2018-11-04 11:41:21 -08:00
'bn.js',
'bs58',
'buffer-layout',
'jayson/lib/client/browser',
'node-fetch',
'rpc-websockets',
'superstruct',
'tweetnacl',
'url',
];
break;
default:
throw new Error(`Unknown configType: ${configType}`);
2018-08-22 21:43:32 -07:00
}
return config;
}
2018-11-04 11:41:21 -08:00
export default [generateConfig('node'), generateConfig('browser')];