diff --git a/grafana-plugin/package.json b/grafana-plugin/package.json index ca3f5711..8716fc34 100644 --- a/grafana-plugin/package.json +++ b/grafana-plugin/package.json @@ -19,8 +19,8 @@ "test:e2e:gen": "yarn playwright codegen http://localhost:3000", "e2e-show-report": "yarn playwright show-report", "generate-types": "cd ./src/network/oncall-api/types-generator && yarn generate", - "dev": "webpack -c ./.config/webpack/webpack.config.ts --env development", - "watch": "webpack -w -c ./.config/webpack/webpack.config.ts --env development", + "dev": "webpack -c ./webpack.config.ts --env development", + "watch": "webpack -w -c ./webpack.config.ts --env development", "sign": "npx --yes @grafana/sign-plugin@latest", "start": "yarn watch", "plop": "plop", diff --git a/grafana-plugin/webpack.config.ts b/grafana-plugin/webpack.config.ts index d40055df..4965462b 100644 --- a/grafana-plugin/webpack.config.ts +++ b/grafana-plugin/webpack.config.ts @@ -1,7 +1,11 @@ -import type { Configuration } from 'webpack'; +import { Configuration, DefinePlugin, EnvironmentPlugin } from 'webpack'; +import LiveReloadPlugin from 'webpack-livereload-plugin'; import { mergeWithRules, CustomizeRule } from 'webpack-merge'; + import grafanaConfig from './.config/webpack/webpack.config'; +const dotenv = require('dotenv'); + const config = async (env): Promise => { const baseConfig = await grafanaConfig(env); const customConfig = { @@ -24,6 +28,15 @@ const config = async (env): Promise => { watchOptions: { ignored: ['**/node_modules/', '**/dist'], }, + plugins: [ + new EnvironmentPlugin({ + ONCALL_API_URL: null, + }), + new DefinePlugin({ + 'process.env': JSON.stringify(dotenv.config().parsed), + }), + ...(env.development ? [new LiveReloadPlugin({ appendScriptTag: true, useSourceHash: true })] : []), + ], }; return mergeWithRules({ @@ -33,6 +46,7 @@ const config = async (env): Promise => { use: CustomizeRule.Merge, }, }, + plugins: CustomizeRule.Replace, watchOptions: { use: CustomizeRule.Merge, },