chore: project config changes for typescript migration
This commit is contained in:
committed by
Justin Starry
parent
3ea23fe736
commit
3eb9f7b3eb
@ -1,31 +1,38 @@
|
||||
import babel from '@rollup/plugin-babel';
|
||||
import commonjs from '@rollup/plugin-commonjs';
|
||||
import copy from 'rollup-plugin-copy';
|
||||
import flowRemoveTypes from 'flow-remove-types';
|
||||
import json from '@rollup/plugin-json';
|
||||
import typescript from 'rollup-plugin-ts';
|
||||
import nodeResolve from '@rollup/plugin-node-resolve';
|
||||
import nodePolyfills from 'rollup-plugin-node-polyfills';
|
||||
import replace from '@rollup/plugin-replace';
|
||||
import {terser} from 'rollup-plugin-terser';
|
||||
|
||||
const env = process.env.NODE_ENV;
|
||||
const extensions = ['.js', '.ts'];
|
||||
|
||||
function generateConfig(configType, format) {
|
||||
const browser = configType === 'browser';
|
||||
const bundle = format === 'iife';
|
||||
const generateTypescript = configType === 'typescript';
|
||||
|
||||
const config = {
|
||||
input: 'src/index.js',
|
||||
input: 'src/index.ts',
|
||||
plugins: [
|
||||
flow(),
|
||||
commonjs(),
|
||||
nodeResolve({
|
||||
browser,
|
||||
preferBuiltins: !browser,
|
||||
dedupe: ['bn.js', 'buffer'],
|
||||
extensions,
|
||||
preferBuiltins: !browser,
|
||||
}),
|
||||
generateTypescript
|
||||
? typescript({
|
||||
browserslist: false,
|
||||
})
|
||||
: undefined,
|
||||
babel({
|
||||
exclude: '**/node_modules/**',
|
||||
extensions,
|
||||
babelHelpers: bundle ? 'bundled' : 'runtime',
|
||||
plugins: bundle ? [] : ['@babel/plugin-transform-runtime'],
|
||||
}),
|
||||
@ -33,9 +40,6 @@ function generateConfig(configType, format) {
|
||||
'process.env.NODE_ENV': JSON.stringify(env),
|
||||
'process.env.BROWSER': JSON.stringify(browser),
|
||||
}),
|
||||
copy({
|
||||
targets: [{src: 'module.d.ts', dest: 'lib', rename: 'index.d.ts'}],
|
||||
}),
|
||||
],
|
||||
onwarn: function (warning, rollupWarn) {
|
||||
if (warning.code !== 'CIRCULAR_DEPENDENCY') {
|
||||
@ -47,6 +51,24 @@ function generateConfig(configType, format) {
|
||||
},
|
||||
};
|
||||
|
||||
if (configType !== 'browser') {
|
||||
// Prevent dependencies from being bundled
|
||||
config.external = [
|
||||
/@babel\/runtime/,
|
||||
'bn.js',
|
||||
'bs58',
|
||||
'buffer-layout',
|
||||
'crypto-hash',
|
||||
'jayson/lib/client/browser',
|
||||
'js-sha3',
|
||||
'node-fetch',
|
||||
'rpc-websockets',
|
||||
'secp256k1',
|
||||
'superstruct',
|
||||
'tweetnacl',
|
||||
];
|
||||
}
|
||||
|
||||
switch (configType) {
|
||||
case 'browser':
|
||||
switch (format) {
|
||||
@ -121,22 +143,12 @@ function generateConfig(configType, format) {
|
||||
sourcemap: true,
|
||||
},
|
||||
];
|
||||
|
||||
// Prevent dependencies from being bundled
|
||||
config.external = [
|
||||
/@babel\/runtime/,
|
||||
'bn.js',
|
||||
'bs58',
|
||||
'buffer-layout',
|
||||
'crypto-hash',
|
||||
'jayson/lib/client/browser',
|
||||
'js-sha3',
|
||||
'node-fetch',
|
||||
'rpc-websockets',
|
||||
'secp256k1',
|
||||
'superstruct',
|
||||
'tweetnacl',
|
||||
];
|
||||
break;
|
||||
case 'typescript':
|
||||
config.output = {
|
||||
file: 'lib/types/index.d.ts',
|
||||
};
|
||||
config.plugins.push(json());
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unknown configType: ${configType}`);
|
||||
@ -147,18 +159,7 @@ function generateConfig(configType, format) {
|
||||
|
||||
export default [
|
||||
generateConfig('node'),
|
||||
generateConfig('typescript'),
|
||||
generateConfig('browser', 'esm'),
|
||||
generateConfig('browser', 'iife'),
|
||||
];
|
||||
|
||||
// Using this instead of rollup-plugin-flow due to
|
||||
// https://github.com/leebyron/rollup-plugin-flow/issues/5
|
||||
function flow() {
|
||||
return {
|
||||
name: 'flow-remove-types',
|
||||
transform: code => ({
|
||||
code: flowRemoveTypes(code).toString(),
|
||||
map: null,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user