mirror of
https://github.com/grafana/grafana.git
synced 2024-12-27 09:21:35 -06:00
012d62782c
fix(packages): prevent import errors by injecting exports.esmodule and check for default prop
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
import resolve from '@rollup/plugin-node-resolve';
|
|
import { createRequire } from 'node:module';
|
|
import path from 'path';
|
|
import copy from 'rollup-plugin-copy';
|
|
import dts from 'rollup-plugin-dts';
|
|
import esbuild from 'rollup-plugin-esbuild';
|
|
import { nodeExternals } from 'rollup-plugin-node-externals';
|
|
import svg from 'rollup-plugin-svg-import';
|
|
|
|
const rq = createRequire(import.meta.url);
|
|
const icons = rq('../../public/app/core/icons/cached.json');
|
|
const pkg = rq('./package.json');
|
|
|
|
const iconSrcPaths = icons.map((iconSubPath) => {
|
|
return `../../public/img/icons/${iconSubPath}.svg`;
|
|
});
|
|
|
|
const legacyOutputDefaults = {
|
|
esModule: true,
|
|
interop: 'compat',
|
|
};
|
|
|
|
export default [
|
|
{
|
|
input: 'src/index.ts',
|
|
plugins: [
|
|
nodeExternals({ deps: true, packagePath: './package.json' }),
|
|
svg({ stringify: true }),
|
|
resolve(),
|
|
copy({
|
|
targets: [{ src: iconSrcPaths, dest: './dist/public/' }],
|
|
flatten: false,
|
|
}),
|
|
esbuild({
|
|
target: 'es2018',
|
|
tsconfig: 'tsconfig.build.json',
|
|
}),
|
|
],
|
|
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-ui/src`),
|
|
...legacyOutputDefaults,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
input: './compiled/index.d.ts',
|
|
plugins: [dts()],
|
|
output: {
|
|
file: pkg.publishConfig.types,
|
|
format: 'es',
|
|
},
|
|
},
|
|
];
|