TypeScript transpiler and module bundler for k6
The main goal of k6pack is to make TypeScript and modern JavaScript features available in k6 tests.
Features
- Supports TypeScript (.ts) and JavaScript (.js) input
- Supports remote (https) modules
- Single executable file, no external dependencies
- No Node.js installation required
Precompiled binaries can be downloaded and installed from the Releases page.
If you have a go development environment, the installation can also be done with the following command:
go install github.com/grafana/k6pack/cmd/k6pack@latest
The name of the entry point must be specified as a parameter. The k6 compatible script is sent to the standard output, so it can be executed directly with k6.
k6pack script.ts | k6 run -
script.ts
import { User, newUser } from "./user";
export default () => {
const user: User = newUser("John");
console.log(user);
};
user.ts
interface User {
name: string;
id: number;
}
class UserAccount implements User {
name: string;
id: number;
constructor(name: string) {
this.name = name;
this.id = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
}
}
function newUser(name: string): User {
return new UserAccount(name);
}
export { User, newUser };
TypeScript transpiler and module bundler for k6.
Bundle TypeScript/JavaScript sources into a single k6 test script.
sourcemap
Sourcemap is disabled by default. If sourcemap is enabled, the current directory will be set in the sourcemap as the source root directory. This can be changed by using the --source-root
flag. You can even disable the source root setting by specifying the empty string.
k6pack [flags] filename
--external stringArray exclude module(s) from the bundle
-h, --help help for k6pack
--minify minify the output
-o, --output string write output to file (default stdout)
--source-root string sets the sourceRoot field in generated source maps (default ".")
--sourcemap emit the source map with an inline data URL
--timeout duration HTTP timeout for remote modules (default 30s)
--typescript force TypeScript loader
Under the hood, k6pack uses the esbuild library. A special esbuild plugin contains k6 specific configuration and another esbuild plugin implements loading from http/https URL.
k6pack can also be used as a go library.
If you want to contribute or help with the development of k6pack, start by reading CONTRIBUTING.md.