diff --git a/src/cli-main.ts b/src/cli-main.ts index e585fd78..dc17d34f 100644 --- a/src/cli-main.ts +++ b/src/cli-main.ts @@ -97,6 +97,9 @@ export async function main(options: Options = {}) { const external = ensureArray(flags.external) options.external = external } + if (flags.target) { + options.target = flags.target.indexOf(',') >= 0 ? flags.target.split(',') : flags.target + } if (flags.dts || flags.dtsResolve || flags.dtsOnly) { options.dts = {} if (typeof flags.dts === 'string') { diff --git a/src/options.ts b/src/options.ts index 518061a8..6d9850cd 100644 --- a/src/options.ts +++ b/src/options.ts @@ -37,7 +37,7 @@ export type Options = { * * default to `node12` */ - target?: string + target?: string | string[] minify?: boolean minifyWhitespace?: boolean minifyIdentifiers?: boolean diff --git a/test/index.test.ts b/test/index.test.ts index 2abe9501..9ac7158b 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -760,3 +760,20 @@ test('es5 target', async (t) => { t.regex(output, /createClass/) t.deepEqual(outFiles, ['input.js']) }) + +test('multiple targets', async (t) => { + const { output, outFiles } = await run( + t.title, + { + 'input.ts': ` + export const answer = 42 + ` + }, + { + entry: ['input.ts'], + flags: ['--target', 'es2020,chrome58,firefox57,safari11,edge16'], + } + ) + t.snapshot(output) + t.deepEqual(outFiles, ['input.js']) +}) diff --git a/test/snapshots/index.test.ts.md b/test/snapshots/index.test.ts.md index 0aadba81..d65e0d6f 100644 --- a/test/snapshots/index.test.ts.md +++ b/test/snapshots/index.test.ts.md @@ -41,38 +41,6 @@ Generated by [AVA](https://avajs.dev). export { MarkRequired };␊ ` -## es5 target - -> Snapshot 1 - - `var __defProp = Object.defineProperty;␊ - var __markAsModule = function (target) { return __defProp(target, "__esModule", { value: true }); };␊ - var __export = function (target, all) {␊ - __markAsModule(target);␊ - for (var name in all)␊ - { __defProp(target, name, { get: all[name], enumerable: true }); }␊ - };␊ - ␊ - // input.ts␊ - __export(exports, {␊ - Foo: function () { return Foo; }␊ - });␊ - var Foo = /*@__PURE__*/(function () {␊ - function Foo () {}␊ - ␊ - Foo.prototype.hi = function hi () {␊ - var a = function () { return "foo"; };␊ - console.log(a());␊ - };␊ - ␊ - return Foo;␊ - }());␊ - // Annotate the CommonJS export names for ESM import in node:␊ - 0 && (module.exports = {␊ - Foo: Foo␊ - });␊ - ` - ## multiple formats > Snapshot 1 @@ -468,3 +436,58 @@ Generated by [AVA](https://avajs.dev). ␊ export { bar };␊ ` + +## es5 target + +> Snapshot 1 + + `var __defProp = Object.defineProperty;␊ + var __markAsModule = function (target) { return __defProp(target, "__esModule", { value: true }); };␊ + var __export = function (target, all) {␊ + __markAsModule(target);␊ + for (var name in all)␊ + { __defProp(target, name, { get: all[name], enumerable: true }); }␊ + };␊ + ␊ + // input.ts␊ + __export(exports, {␊ + Foo: function () { return Foo; }␊ + });␊ + var Foo = /*@__PURE__*/(function () {␊ + function Foo () {}␊ + ␊ + Foo.prototype.hi = function hi () {␊ + var a = function () { return "foo"; };␊ + console.log(a());␊ + };␊ + ␊ + return Foo;␊ + }());␊ + // Annotate the CommonJS export names for ESM import in node:␊ + 0 && (module.exports = {␊ + Foo: Foo␊ + });␊ + ` + +## multiple targets + +> Snapshot 1 + + `var __defProp = Object.defineProperty;␊ + var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });␊ + var __export = (target, all) => {␊ + __markAsModule(target);␊ + for (var name in all)␊ + __defProp(target, name, { get: all[name], enumerable: true });␊ + };␊ + ␊ + // input.ts␊ + __export(exports, {␊ + answer: () => answer␊ + });␊ + var answer = 42;␊ + // Annotate the CommonJS export names for ESM import in node:␊ + 0 && (module.exports = {␊ + answer␊ + });␊ + ` diff --git a/test/snapshots/index.test.ts.snap b/test/snapshots/index.test.ts.snap index e622ded7..e4d2e82f 100644 Binary files a/test/snapshots/index.test.ts.snap and b/test/snapshots/index.test.ts.snap differ