napi-rs/rollup.config.js

70 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-11-19 15:58:21 +09:00
import { readFileSync } from 'fs'
import { join } from 'path'
import alias from '@rollup/plugin-alias'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import nodeResolve from '@rollup/plugin-node-resolve'
import replace from '@rollup/plugin-replace'
import toml from 'toml'
const NAPI_CARGO_TOML = readFileSync(
join(__dirname, 'crates', 'napi', 'Cargo.toml'),
'utf8',
)
const NAPI_DERIVE_CARGO_TOML = readFileSync(
join(__dirname, 'crates', 'macro', 'Cargo.toml'),
'utf8',
)
const NAPI_BUILD_CARGO_TOML = readFileSync(
join(__dirname, 'crates', 'build', 'Cargo.toml'),
'utf8',
)
const {
package: { version: NAPI_VERSION },
} = toml.parse(NAPI_CARGO_TOML)
const {
package: { version: NAPI_DERIVE_VERSION },
} = toml.parse(NAPI_DERIVE_CARGO_TOML)
const {
package: { version: NAPI_BUILD_VERSION },
} = toml.parse(NAPI_BUILD_CARGO_TOML)
console.info('napi version: ', NAPI_VERSION)
console.info('napi-derive version: ', NAPI_DERIVE_VERSION)
console.info('napi-build version: ', NAPI_BUILD_VERSION)
export default {
input: './scripts/cli/src/index.js',
inlineDynamicImports: true,
output: {
banner: '#!/usr/bin/env node',
file: './cli/scripts/index.js',
format: 'cjs',
sourcemap: 'inline',
},
plugins: [
replace({
NAPI_VERSION,
NAPI_DERIVE_VERSION,
NAPI_BUILD_VERSION,
2022-04-27 01:31:40 +09:00
// Do not external `node:xx` because we need to replace it with `xx` to compatible with `node@12`
2022-02-08 10:57:22 +09:00
'node:path': 'path',
'node:os': 'os',
'node:process': 'process',
2022-04-27 01:31:40 +09:00
'node:tty': 'tty',
2021-11-19 15:58:21 +09:00
preventAssignment: true,
}),
alias({
entries: [{ find: 'readable-stream', replacement: 'stream' }],
}),
2022-04-27 01:31:40 +09:00
nodeResolve({
preferBuiltins: true,
exportConditions: ['node', 'default', 'module', 'export'],
}),
2021-11-19 15:58:21 +09:00
commonjs(),
json(),
],
}