2024-04-12 19:20:14 +08:00
|
|
|
import { builtinModules, createRequire } from 'node:module';
|
|
|
|
import esbuild from 'rollup-plugin-esbuild';
|
|
|
|
import process from 'node:process';
|
|
|
|
import dts from 'rollup-plugin-dts';
|
|
|
|
import resolve from '@rollup/plugin-node-resolve';
|
|
|
|
import commonjs from '@rollup/plugin-commonjs';
|
|
|
|
import json from '@rollup/plugin-json';
|
|
|
|
import { defineConfig } from 'rollup';
|
|
|
|
|
|
|
|
const require = createRequire(import.meta.url);
|
|
|
|
const pkg = require('./package.json');
|
|
|
|
|
|
|
|
const entries = {
|
|
|
|
cli: 'src/cli.ts',
|
2024-04-17 17:01:42 +08:00
|
|
|
index: 'src/index.ts',
|
2024-04-12 19:20:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const external = [
|
|
|
|
...builtinModules,
|
|
|
|
...Object.keys(pkg.dependencies || {}),
|
|
|
|
...Object.keys(pkg.peerDependencies || {}),
|
|
|
|
'pathe',
|
|
|
|
'birpc',
|
|
|
|
'vite',
|
|
|
|
'node:url',
|
|
|
|
'node:events',
|
|
|
|
'node:vm',
|
|
|
|
];
|
|
|
|
|
|
|
|
const plugins = [
|
|
|
|
resolve({
|
|
|
|
preferBuiltins: true,
|
|
|
|
}),
|
|
|
|
json(),
|
|
|
|
commonjs(),
|
|
|
|
esbuild({
|
|
|
|
target: 'esnext',
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
|
|
|
|
const configs = defineConfig([
|
|
|
|
{
|
|
|
|
input: entries,
|
|
|
|
output: {
|
|
|
|
dir: 'dist',
|
|
|
|
format: 'esm',
|
|
|
|
entryFileNames: '[name].mjs',
|
2024-04-15 23:04:43 +08:00
|
|
|
preserveModules: true,
|
|
|
|
preserveModulesRoot: './src',
|
2024-04-12 19:20:14 +08:00
|
|
|
},
|
|
|
|
external,
|
|
|
|
plugins,
|
|
|
|
onwarn,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
if (!process.env.BUILD_NO_DTS) {
|
|
|
|
configs.push({
|
|
|
|
input: entries,
|
|
|
|
output: {
|
|
|
|
dir: 'dist',
|
|
|
|
entryFileNames: '[name].d.ts',
|
2024-04-15 23:04:43 +08:00
|
|
|
preserveModules: true,
|
|
|
|
preserveModulesRoot: './src',
|
2024-04-12 19:20:14 +08:00
|
|
|
format: 'esm',
|
|
|
|
},
|
|
|
|
external,
|
|
|
|
plugins: [dts({ respectExternal: true })],
|
|
|
|
onwarn,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export default configs;
|
|
|
|
|
|
|
|
function onwarn(message) {
|
|
|
|
if (['EMPTY_BUNDLE', 'CIRCULAR_DEPENDENCY'].includes(message.code)) return;
|
|
|
|
console.error(message);
|
|
|
|
}
|