From b0b09e04b35487090109e2a76e6b9b3ef3e449ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Han=EF=BC=88=E3=83=8F=E3=83=B3=EF=BC=89?= Date: Fri, 10 Dec 2021 22:55:23 +0900 Subject: [PATCH] feat: support alias and esbuild config (#29) Co-authored-by: Pooya Parsa --- src/build.ts | 4 ++++ src/builder/rollup.ts | 9 +++++---- src/types.ts | 3 +++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/build.ts b/src/build.ts index 73fc7b3a..1f61b436 100644 --- a/src/build.ts +++ b/src/build.ts @@ -37,7 +37,11 @@ export async function build (rootDir: string, stub: boolean, inputConfig: BuildC dependencies: [], devDependencies: [], peerDependencies: [], + alias: {}, rollup: { + esbuild: { + target: 'es2020' + }, emitCJS: false, cjsBridge: false, inlineDependencies: false diff --git a/src/builder/rollup.ts b/src/builder/rollup.ts index 172c1641..38129c52 100644 --- a/src/builder/rollup.ts +++ b/src/builder/rollup.ts @@ -146,7 +146,10 @@ export function getRollupOptions (ctx: BuildContext): RollupOptions { plugins: [ alias({ - [ctx.pkg.name!]: ctx.options.rootDir + entries: { + [ctx.pkg.name!]: ctx.options.rootDir, + ...ctx.options.alias + } }), nodeResolve({ @@ -160,9 +163,7 @@ export function getRollupOptions (ctx: BuildContext): RollupOptions { shebangPlugin(), - esbuild({ - target: 'es2020' - }), + esbuild(ctx.options.rollup.esbuild), commonjs({ extensions, diff --git a/src/types.ts b/src/types.ts index a0e0466e..e2c18af2 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3,6 +3,7 @@ import type { PackageJson } from 'pkg-types' import type { Hookable } from 'hookable' import type { RollupOptions, RollupBuild } from 'rollup' import type { MkdistOptions } from 'mkdist' +import type { Options as EsbuildOptions } from 'rollup-plugin-esbuild' import { Schema } from 'untyped' export interface BaseBuildEntry { @@ -34,6 +35,7 @@ export interface RollupBuildOptions { emitCJS?: boolean cjsBridge?: boolean inlineDependencies?: boolean + esbuild: EsbuildOptions } export interface BuildOptions { @@ -47,6 +49,7 @@ export interface BuildOptions { dependencies: string[] peerDependencies: string[] devDependencies: string[] + alias: { [find: string]: string }, rollup: RollupBuildOptions }