102 lines
2.4 KiB
JavaScript
102 lines
2.4 KiB
JavaScript
import typescript from '@rollup/plugin-typescript';
|
|
import resolve from '@rollup/plugin-node-resolve';
|
|
import commonjs from '@rollup/plugin-commonjs';
|
|
import { dts } from 'rollup-plugin-dts';
|
|
import json from '@rollup/plugin-json';
|
|
import path from 'path';
|
|
import alias from '@rollup/plugin-alias';
|
|
import esbuild from 'rollup-plugin-esbuild';
|
|
import replace from '@rollup/plugin-replace';
|
|
import * as glob from 'glob';
|
|
import inject from 'rollup-plugin-inject';
|
|
|
|
/**
|
|
* @type {import('rollup').RollupOptions}
|
|
*/
|
|
const config = {
|
|
input: './src/app.ts',
|
|
output: {
|
|
dir: './dist',
|
|
entryFileNames: 'app.mjs',
|
|
chunkFileNames: '[name]-[hash].mjs',
|
|
format: 'esm',
|
|
},
|
|
plugins: [
|
|
resolve(),
|
|
commonjs(),
|
|
esbuild({
|
|
target: 'node22', // 目标为 Node.js 14
|
|
minify: false, // 启用代码压缩
|
|
tsconfig: 'tsconfig.json',
|
|
}),
|
|
json(),
|
|
],
|
|
external: [],
|
|
};
|
|
const dtsConfig = {
|
|
input: './src/app.ts',
|
|
output: {
|
|
file: './dist/app.d.ts',
|
|
format: 'esm',
|
|
},
|
|
plugins: [dts()],
|
|
};
|
|
const program = {
|
|
input: './src/run.ts',
|
|
output: {
|
|
dir: './dist',
|
|
entryFileNames: 'run.mjs',
|
|
chunkFileNames: '[name]-[hash].mjs',
|
|
format: 'esm',
|
|
banner: `
|
|
import { fileURLToPath as fileURLToPath2, pathToFileURL as pathToFileURL2} from 'url';
|
|
const __filename = fileURLToPath2(import.meta.url);
|
|
const __dirname = dirname(__filename);`,
|
|
},
|
|
plugins: [
|
|
resolve(),
|
|
commonjs(),
|
|
esbuild({
|
|
target: 'node22', // 目标为 Node.js 14
|
|
minify: false, // 启用代码压缩
|
|
tsconfig: 'tsconfig.json',
|
|
}),
|
|
json(),
|
|
],
|
|
external: ['rollup'],
|
|
};
|
|
const configs = glob.sync('./src/**/*config.ts').map((input) => {
|
|
const name = path.basename(input, '.ts');
|
|
const code = {
|
|
input,
|
|
output: {
|
|
dir: './dist',
|
|
entryFileNames: `${name}.mjs`,
|
|
chunkFileNames: '[name]-[hash].mjs',
|
|
format: 'esm',
|
|
},
|
|
plugins: [
|
|
resolve(),
|
|
commonjs(),
|
|
esbuild({
|
|
target: 'node22', // 目标为 Node.js 14
|
|
minify: false, // 启用代码压缩
|
|
tsconfig: 'tsconfig.json',
|
|
}),
|
|
json(),
|
|
],
|
|
external: [],
|
|
};
|
|
const codeDts = {
|
|
input,
|
|
output: {
|
|
file: `./dist/${name}.d.ts`,
|
|
format: 'esm',
|
|
},
|
|
plugins: [dts()],
|
|
};
|
|
return [code, codeDts];
|
|
});
|
|
const allConfigs = configs.flat();
|
|
export default [config, dtsConfig, program, ...allConfigs];
|