Skip to content

Commit

Permalink
chore: add webpack configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
dextertanyj committed Aug 21, 2023
1 parent 0dc47a8 commit c6ca8f3
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ check(response, {
});
```

**4. Bundle your test.**

Refer to [k6-template-typescript](https://github.com/grafana/k6-template-typescript) on how to configure your bundler to emit `k6` compatible code.

Use the following regex to ensure that `k6-trpc` is bundled together in the output and is not treated as an external dependency.

```javascript
{
// Other webpack configuration parameters.
externals: /^(k6|https?\:\/\/)(\/.*)?(?!-trpc)/,
}
```

> Alternatively, refer to `webpack.config.js.example` for a sample webpack configuration.
## Configuration

`createClient` accepts a `transformer` argument which allows you to use `SuperJSON` or any other tRPC-compliant transformer.
Expand Down
50 changes: 50 additions & 0 deletions webpack.config.js.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const GlobEntries = require('webpack-glob-entries');

module.exports = {
mode: 'production',
entry: GlobEntries('./src/*test*.ts'), // Generates multiple entry for each test
output: {
path: path.join(__dirname, 'build'),
libraryTarget: 'commonjs',
filename: '[name].js',
},
resolve: {
extensions: ['.ts', '.js'],
},
module: {
rules: [
{
test: /\.ts$/,
use: {
loader: 'babel-loader',
options: {
presets: [
"@babel/preset-env",
"@babel/preset-typescript"
],
plugins: [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread"
]
}
},
exclude: /node_modules/,
},
],
},
externals: /^(k6|https?\:\/\/)(\/.*)?(?!-trpc)/,
// Generate map files for compiled scripts
devtool: "source-map",
stats: {
colors: true,
},
plugins: [
new CleanWebpackPlugin(),
],
optimization: {
// Don't minimize, as it's not used in the browser
minimize: false,
},
};

0 comments on commit c6ca8f3

Please sign in to comment.