mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 02:10:45 -06:00
012d62782c
fix(packages): prevent import errors by injecting exports.esmodule and check for default prop
56 lines
1.4 KiB
TypeScript
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',
|
|
},
|
|
},
|
|
];
|