-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* restore rollup.config.ts * separate config for walletlib
- Loading branch information
1 parent
97eb85a
commit be1ddb3
Showing
3 changed files
with
104 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
js/packages/mobile-wallet-adapter-walletlib/rollup.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import alias from '@rollup/plugin-alias'; | ||
import commonJsPlugin from '@rollup/plugin-commonjs'; | ||
import nodeResolve from '@rollup/plugin-node-resolve'; | ||
import replace from '@rollup/plugin-replace'; | ||
import fs from 'fs'; | ||
import * as path from 'path'; | ||
import type { RollupOptions } from 'rollup'; | ||
import externals from 'rollup-plugin-node-externals'; | ||
import ts from 'rollup-plugin-ts'; | ||
|
||
function createConfig({ | ||
bundleName, | ||
format, | ||
runtime, | ||
}: { | ||
bundleName: string; | ||
format: 'cjs' | 'esm'; | ||
runtime: 'node' | 'react-native'; | ||
}): RollupOptions { | ||
return { | ||
input: 'src/index.ts', | ||
output: { | ||
file: 'lib/' + format + '/' + bundleName, | ||
format, | ||
}, | ||
plugins: [ | ||
alias({ | ||
entries: [ | ||
{ | ||
find: /^\./, // Relative paths. | ||
replacement: '.', | ||
async customResolver(source, importer, options) { | ||
const resolved = await this.resolve(source, importer, { | ||
skipSelf: true, | ||
...options, | ||
}); | ||
if (resolved == null) { | ||
return; | ||
} | ||
const { id: resolvedId } = resolved; | ||
const directory = path.dirname(resolvedId); | ||
const moduleFilename = path.basename(resolvedId); | ||
const forkPath = path.join(directory, '__forks__', runtime, moduleFilename); | ||
const hasForkCacheKey = `has_fork:${forkPath}`; | ||
let hasFork = this.cache.get(hasForkCacheKey); | ||
if (hasFork === undefined) { | ||
hasFork = fs.existsSync(forkPath); | ||
this.cache.set(hasForkCacheKey, hasFork); | ||
} | ||
if (hasFork) { | ||
return forkPath; | ||
} | ||
}, | ||
}, | ||
], | ||
}), | ||
externals(), | ||
nodeResolve({ | ||
browser: false, | ||
extensions: ['.ts'], | ||
preferBuiltins: runtime === 'node', | ||
}), | ||
replace({ | ||
preventAssignment: true, | ||
values: { | ||
'process.env.BROWSER': JSON.stringify(false), | ||
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV), | ||
}, | ||
}), | ||
ts({ | ||
tsconfig: format === 'cjs' ? 'tsconfig.cjs.json' : 'tsconfig.json', | ||
}), | ||
commonJsPlugin({ exclude: 'node_modules', extensions: ['.js', '.ts'] }), | ||
], | ||
}; | ||
} | ||
|
||
const config: RollupOptions[] = [ | ||
createConfig({ bundleName: 'index.js', format: 'esm', runtime: 'node' }), | ||
createConfig({ | ||
bundleName: 'index.native.js', | ||
format: 'esm', | ||
runtime: 'react-native', | ||
}), | ||
]; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters