Skip to content

Commit e345e1c

Browse files
committed
docs(example): update readme
1 parent 2a5af36 commit e345e1c

File tree

1 file changed

+51
-11
lines changed

1 file changed

+51
-11
lines changed

example/README.md

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,62 @@ HAWK_TOKEN = ""
99

1010
Then, get it in node process through the [dotenv](https://github.com/motdotla/dotenv) package.
1111

12-
```js
13-
// webpack.config.js
14-
const HawkWebpackPlugin = require('@hawk.so/webpack-plugin');
15-
const dotenv = require('dotenv');
12+
```cjs
13+
// webpack.config.cjs
1614

17-
dotenv.config()
15+
const path = require("path");
16+
const webpack = require("webpack");
17+
const HtmlWebpackPlugin = require("html-webpack-plugin");
18+
const TerserPlugin = require("terser-webpack-plugin");
19+
const HawkWebpackPlugin = require("@hawk.so/webpack-plugin");
20+
21+
/**
22+
* Add ability to use .env file in webpack.config.cjs
23+
* It is used to get HAWK_TOKEN from env variables
24+
*/
25+
require('dotenv').config();
26+
27+
/**
28+
* Create a random release key that will be used in HawkWebpackPlugin and in HawkCatcher
29+
*/
30+
const releaseKey = [...Array(10)].map(() => Math.random().toString(36)[2]).join('');
1831

1932
module.exports = {
33+
mode: "production",
34+
entry: "./src/index.js",
35+
output: {
36+
filename: "bundle.js",
37+
path: path.resolve(__dirname, "dist"),
38+
clean: true,
39+
},
2040
plugins: [
2141
new HawkWebpackPlugin({
22-
integrationToken: process.env.HAWK_TOKEN
23-
})
42+
integrationToken: process.env.HAWK_TOKEN,
43+
release: releaseKey,
44+
}),
45+
new HtmlWebpackPlugin({
46+
template: "./index.html",
47+
}),
48+
49+
/**
50+
* Replace HAWK_TOKEN and RELEASE with actual values
51+
* It is used for cathcer to get hawk token and release key
52+
*/
53+
new webpack.DefinePlugin({
54+
'HAWK_TOKEN': JSON.stringify(process.env.HAWK_TOKEN),
55+
'RELEASE': JSON.stringify(releaseKey),
56+
}),
2457
],
25-
devtool: 'hidden-source-map',
26-
}
58+
optimization: {
59+
minimize: true,
60+
minimizer: [new TerserPlugin()],
61+
},
62+
devtool: "hidden-source-map",
63+
};
64+
2765
```
2866

29-
The release id is not specified manually, so the plugin will use webpack compilation hash.
30-
We'll access it through the `release.json` file, that will be created at the output directory.
67+
In this example we pass the manually created release key to the HawkWebpackPlugin.
68+
69+
If the release id is not specified manually, then the plugin will use webpack compilation hash.
70+
We'll could access it through the `release.json` file, that will be created at the output directory.

0 commit comments

Comments
 (0)