fix: web3.js browser cjs build (#23500)

This commit is contained in:
Jordan Sexton 2022-03-11 14:35:15 -07:00 committed by GitHub
parent ccff006948
commit 3cf31fa9b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 25 deletions

View File

@ -69,8 +69,34 @@ function generateConfig(configType, format) {
switch (configType) {
case 'browser':
switch (format) {
case 'esm': {
case 'iife': {
config.external = ['http', 'https'];
config.output = [
{
file: 'lib/index.iife.js',
format: 'iife',
name: 'solanaWeb3',
sourcemap: true,
},
{
file: 'lib/index.iife.min.js',
format: 'iife',
name: 'solanaWeb3',
sourcemap: true,
plugins: [terser({mangle: false, compress: false})],
},
];
break;
}
default: {
config.output = [
{
file: 'lib/index.browser.cjs.js',
format: 'cjs',
sourcemap: true,
},
{
file: 'lib/index.browser.esm.js',
format: 'es',
@ -99,29 +125,6 @@ function generateConfig(configType, format) {
break;
}
case 'iife': {
config.external = ['http', 'https'];
config.output = [
{
file: 'lib/index.iife.js',
format: 'iife',
name: 'solanaWeb3',
sourcemap: true,
},
{
file: 'lib/index.iife.min.js',
format: 'iife',
name: 'solanaWeb3',
sourcemap: true,
plugins: [terser({mangle: false, compress: false})],
},
];
break;
}
default:
throw new Error(`Unknown format: ${format}`);
}
// TODO: Find a workaround to avoid resolving the following JSON file:
@ -152,6 +155,6 @@ function generateConfig(configType, format) {
export default [
generateConfig('node'),
generateConfig('browser', 'esm'),
generateConfig('browser'),
generateConfig('browser', 'iife'),
];