-
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
96 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { ModuleFormat } from 'rollup' | ||
import { Target as EsbuildTarget } from 'esbuild' | ||
import hashbangPlugin from 'rollup-plugin-hashbang' | ||
import esbuildPlugin from 'rollup-plugin-esbuild' | ||
import commonjsPlugin from '@rollup/plugin-commonjs' | ||
import dtsPlugin from 'rollup-plugin-dts' | ||
import { resolvePlugin } from './resolve-plugin' | ||
|
||
type Options = { | ||
bundle?: boolean | ||
dts?: boolean | ||
target?: EsbuildTarget | ||
watch?: boolean | ||
minify?: boolean | ||
jsxFactory?: string | ||
jsxFragment?: string | ||
outDir: string | ||
format: ModuleFormat | ||
} | ||
|
||
export async function createRollupConfigs(files: string[], options: Options) { | ||
const getRollupConfig = ({ dts }: { dts?: boolean }) => { | ||
return { | ||
inputConfig: { | ||
input: files, | ||
plugins: [ | ||
hashbangPlugin(), | ||
resolvePlugin({ bundle: options.bundle }), | ||
commonjsPlugin(), | ||
!dts && | ||
esbuildPlugin({ | ||
target: options.target, | ||
watch: options.watch, | ||
minify: options.minify, | ||
jsxFactory: options.jsxFactory, | ||
jsxFragment: options.jsxFragment, | ||
}), | ||
dts && dtsPlugin(), | ||
].filter(Boolean), | ||
}, | ||
outputConfig: { | ||
dir: options.outDir, | ||
format: options.format, | ||
}, | ||
} | ||
} | ||
const rollupConfigs = [getRollupConfig({})] | ||
|
||
if (options.dts) { | ||
rollupConfigs.push(getRollupConfig({ dts: true })) | ||
} | ||
|
||
return rollupConfigs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {spawn} from 'child_process' | ||
|
||
export function runCode(filename: string, { | ||
args | ||
}: {args: string[]}) { | ||
spawn('node', [filename, ...args], { | ||
stdio: 'inherit' | ||
}) | ||
} |