grafana/packages/grafana-prometheus/rollup.config.ts
Jack Westbrook 012d62782c
Fix: Prevent import errors caused by Rollup 4 (#93903)
fix(packages): prevent import errors by injecting exports.esmodule and check for default prop
2024-09-27 12:18:52 +01:00

56 lines
1.4 KiB
TypeScript

import image from '@rollup/plugin-image';
import resolve from '@rollup/plugin-node-resolve';
import { createRequire } from 'node:module';
import path from 'path';
import dts from 'rollup-plugin-dts';
import esbuild from 'rollup-plugin-esbuild';
import { nodeExternals } from 'rollup-plugin-node-externals';
const rq = createRequire(import.meta.url);
const pkg = rq('./package.json');
const legacyOutputDefaults = {
esModule: true,
interop: 'compat',
};
export default [
{
input: 'src/index.ts',
plugins: [
nodeExternals({ deps: true, packagePath: './package.json' }),
resolve(),
esbuild({
target: 'es2018',
tsconfig: 'tsconfig.build.json',
}),
image(),
],
output: [
{
format: 'cjs',
sourcemap: true,
dir: path.dirname(pkg.publishConfig.main),
...legacyOutputDefaults,
},
{
format: 'esm',
sourcemap: true,
dir: path.dirname(pkg.publishConfig.module),
preserveModules: true,
// @ts-expect-error (TS cannot assure that `process.env.PROJECT_CWD` is a string)
preserveModulesRoot: path.join(process.env.PROJECT_CWD, `packages/grafana-prometheus/src`),
...legacyOutputDefaults,
},
],
},
{
input: './compiled/index.d.ts',
plugins: [dts()],
output: {
file: pkg.publishConfig.types,
format: 'es',
},
},
];