Skip to content

ROX-29843: Minimal webpack config to build OCP dynamic plugin#15944

Merged
dvail merged 3 commits intomasterfrom
dv/ROX-29843-ocp-plugin-conf-poc
Jul 24, 2025
Merged

ROX-29843: Minimal webpack config to build OCP dynamic plugin#15944
dvail merged 3 commits intomasterfrom
dv/ROX-29843-ocp-plugin-conf-poc

Conversation

@dvail
Copy link
Copy Markdown
Contributor

@dvail dvail commented Jul 8, 2025

Description

Adds webpack configuration and required dependencies to build a "Hello world" OCP plugin.

User-facing documentation

Testing and quality

  • the change is production ready: the change is GA, or otherwise the functionality is gated by a feature flag
  • CI results are inspected

Automated testing

Test running the plugin with webpack in development mode:

$ npm run start:ocp-plugin

> @stackrox/platform-app@0.0.0 start:ocp-plugin
> NODE_ENV=development webpack serve --config webpack.ocp-plugin.config.js

<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: http://localhost:9001/, http://[::1]:9001/
<i> [webpack-dev-server] On Your Network (IPv4): http://10.0.0.157:9001/
<i> [webpack-dev-server] Content not from webpack is served from '/Users/dvail/go/src/github.com/stackrox/stackrox/ui/apps/platform/public' directory
assets by chunk 1.55 MiB (id hint: vendors)
  asset vendors-node_modules_patternfly_react-core_dist_esm_helpers_util_js-chunk.js 1.03 MiB [emitted] (id hint: vendors) 1 related asset
  asset vendors-node_modules_patternfly_react-core_dist_esm_components_Tooltip_Tooltip_js-chunk.js 184 KiB [emitted] (id hint: vendors) 1 related asset
  asset vendors-node_modules_patternfly_react-core_dist_esm_components_Page_index_js-chunk.js 171 KiB [emitted] (id hint: vendors) 1 related asset
  asset vendors-node_modules_css-loader_dist_runtime_api_js-node_modules_css-loader_dist_runtime_sour-493a42-chunk.js 53 KiB [emitted] (id hint: vendors) 1 related asset
  asset vendors-node_modules_patternfly_react-core_dist_esm_layouts_Flex_index_js-chunk.js 40.9 KiB [emitted] (id hint: vendors) 1 related asset
  asset vendors-node_modules_patternfly_react-core_dist_esm_components_Label_index_js-chunk.js 36.1 KiB [emitted] (id hint: vendors) 1 related asset
  asset vendors-node_modules_patternfly_react-core_dist_esm_components_Button_Button_js-node_modules_-140973-chunk.js 25.7 KiB [emitted] (id hint: vendors) 1 related asset
  asset vendors-node_modules_tslib_tslib_es6_mjs-chunk.js 20.2 KiB [emitted] (id hint: vendors) 1 related asset
+ 23 assets
orphan modules 20.3 KiB [orphan] 31 modules
runtime modules 59 KiB 16 modules
modules by path ../node_modules/ 1.47 MiB 163 modules
consume-shared-module modules 630 bytes
  modules by path consume shared module (default) @patternfly/react-core/dist/dynamic/ 294 bytes 7 modules
  modules by path consume shared module (default) @patternfly/react-icons/dist/dynamic/icons/ 294 bytes 7 modules
  consume shared module (default) react@^17.0.1 (singleton) 42 bytes [built] [code generated]
provide-module modules 588 bytes
  modules by path provide shared module (default) @patternfly/react-core/dist/dynamic/ 294 bytes 7 modules
  modules by path provide shared module (default) @patternfly/react-icons/dist/dynamic/icons/ 294 bytes 7 modules
modules by path ./ 13.2 KiB
  modules by path ./Containers/Vulnerabilities/components/ 8.23 KiB 3 modules
  + 3 modules
container entry 42 bytes [built] [code generated]

LOG from @openshift-console/dynamic-plugin-sdk-webpack/lib/webpack/loaders/dynamic-module-import-loader ../node_modules/ts-loader/index.js??ruleSet[1].rules[0].use[0]!./Components/PatternFly/SeverityIcons.tsx
<w> Non-index and non-dynamic module import @patternfly/react-icons/dist/esm/createIcon

webpack 5.100.2 compiled successfully in 907 ms

Test building the plugin for production with webpack:

$ npm run build:ocp-plugin

> @stackrox/platform-app@0.0.0 build:ocp-plugin
> tsc && NODE_ENV=production webpack --config webpack.ocp-plugin.config.js

assets by chunk 248 KiB (id hint: vendors)
  asset 551-chunk-138b1f08d4d3eac3d142.min.js 131 KiB [emitted] [immutable] [minimized] (id hint: vendors) 1 related asset
  asset 72-chunk-33e4f97cda30e10c12d2.min.js 44.8 KiB [emitted] [immutable] [minimized] (id hint: vendors) 1 related asset
  asset 619-chunk-a5eb97654c17b5bd4cc4.min.js 26.2 KiB [emitted] [immutable] [minimized] (id hint: vendors)
  asset 860-chunk-4935ef836a401f55d5a9.min.js 25.2 KiB [emitted] [immutable] [minimized] (id hint: vendors)
  asset 491-chunk-a10d17104e03484eeca0.min.js 13.6 KiB [emitted] [immutable] [minimized] (id hint: vendors)
  asset 49-chunk-2309a7adbb784a902d3d.min.js 3.05 KiB [emitted] [immutable] [minimized] (id hint: vendors)
  asset 481-chunk-e60248378c38d526aa5d.min.js 2.62 KiB [emitted] [immutable] [minimized] (id hint: vendors)
  asset 699-chunk-247edb6d9fbe7042b97f.min.js 1.36 KiB [emitted] [immutable] [minimized] (id hint: vendors)
+ 19 assets
orphan modules 291 KiB [orphan] 145 modules
runtime modules 22.7 KiB 12 modules
built modules 478 KiB (javascript) 630 bytes (consume-shared) 588 bytes (share-init) [built]
  javascript modules 478 KiB 42 modules
  consume-shared-module modules 630 bytes
    modules by path consume shared module (default) @patternfly/react-core/dist/dynamic/ 294 bytes 7 modules
    modules by path consume shared module (default) @patternfly/react-icons/dist/dynamic/icons/ 294 bytes
      consume shared module (default) @patternfly/react-icons/dist/dynamic/icons/check...(truncated) 42 bytes [built] [code generated]
      + 6 modules
    consume shared module (default) react@^17.0.1 (singleton) 42 bytes [built] [code generated]
  provide-module modules 588 bytes
    modules by path provide shared module (default) @patternfly/react-core/dist/dynamic/ 294 bytes 7 modules
    modules by path provide shared module (default) @patternfly/react-icons/dist/dynamic/icons/ 294 bytes
      provide shared module (default) @patternfly/react-icons/dist/dynamic/icons/angle...(truncated) 42 bytes [built] [code generated]
      + 6 modules

LOG from @openshift-console/dynamic-plugin-sdk-webpack/lib/webpack/loaders/dynamic-module-import-loader ../node_modules/ts-loader/index.js??ruleSet[1].rules[0].use[0]!./Components/PatternFly/SeverityIcons.tsx
<w> Non-index and non-dynamic module import @patternfly/react-icons/dist/esm/createIcon

webpack 5.100.2 compiled successfully in 2579 ms

Verify that our code is available in plugin files:

$ grep -r "Your plugin is working." ./build
./build/static/ocp-plugin/exposed-SecurityVulnerabilitiesPage-chunk-b998a0624693c004f82e.min.js:"use strict";...{children:[(0,o.jsxs)("span",{className:"console-plugin-template__nice",children:[(0,o.jsx)(i.CheckCircleIcon,{})," ","Success!"]})," ","Your plugin is working."]})})]})}},5292:e=>{var n=[];function t(e){for(var t=-1,o=0;o<n.length;o++)if(n[o].identifier===e){t=o;break}return t}function o(e,o){for(var a={},i=[],l=0;l<e.length;l++)...

@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Jul 8, 2025

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@red-hat-konflux
Copy link
Copy Markdown
Contributor

Caution

There are some errors in your PipelineRun template.

PipelineRun Error
quay-proxy no kind "ImageDigestMirrorSet" is registered for version "config.openshift.io/v1" in scheme "k8s.io/client-go/kubernetes/scheme/register.go:83"

@codecov
Copy link
Copy Markdown

codecov bot commented Jul 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 48.69%. Comparing base (a1280b9) to head (864f29d).
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #15944      +/-   ##
==========================================
+ Coverage   48.66%   48.69%   +0.03%     
==========================================
  Files        2606     2606              
  Lines      191745   191760      +15     
==========================================
+ Hits        93305    93372      +67     
+ Misses      91100    91055      -45     
+ Partials     7340     7333       -7     
Flag Coverage Δ
go-unit-tests 48.69% <ø> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dvail dvail force-pushed the dv/ROX-29843-ocp-plugin-conf-poc branch 4 times, most recently from 2443ef3 to d0060b9 Compare July 15, 2025 14:21
@rhacs-bot
Copy link
Copy Markdown
Contributor

rhacs-bot commented Jul 15, 2025

Images are ready for the commit at 864f29d.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.9.x-303-g864f29d20c.

@dvail dvail force-pushed the dv/ROX-29843-ocp-plugin-conf-poc branch 3 times, most recently from ed1222f to 24c3566 Compare July 15, 2025 19:54
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @dvail - I've reviewed your changes - here's some feedback:

  • Add output.clean: true or use CleanWebpackPlugin in webpack.ocp-plugin.config.js to automatically purge stale build artifacts before each build.
  • Consolidate your alias mappings by sharing tsconfig paths or a common config module instead of duplicating resolve.alias definitions.
  • Move the consolePlugin metadata out of package.json into console-extensions.json to centralize plugin configuration and align with console conventions.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Add output.clean: true or use CleanWebpackPlugin in webpack.ocp-plugin.config.js to automatically purge stale build artifacts before each build.
- Consolidate your alias mappings by sharing tsconfig paths or a common config module instead of duplicating resolve.alias definitions.
- Move the consolePlugin metadata out of package.json into console-extensions.json to centralize plugin configuration and align with console conventions.

## Individual Comments

### Comment 1
<location> `ui/apps/platform/webpack.ocp-plugin.config.js:42` </location>
<code_context>
+        rules: [
+            {
+                test: /\.(jsx?|tsx?)$/,
+                exclude: /\/node_modules\//,
+                use: [
+                    {
</code_context>

<issue_to_address>
The RegExp for 'exclude' may not match all node_modules paths as intended.

The current RegExp may not exclude all node_modules directories, particularly on Windows or with nested paths. Consider a more general pattern like /node_modules/ or simply 'node_modules' for better compatibility.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
                exclude: /\/node_modules\//,
=======
                exclude: /node_modules/,
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dvail dvail force-pushed the dv/ROX-29843-ocp-plugin-conf-poc branch from 24c3566 to 463c840 Compare July 15, 2025 20:18
@dvail dvail force-pushed the dv/ROX-29843-ocp-plugin-conf-poc branch from 463c840 to 5aa0b7b Compare July 17, 2025 18:10
@dvail dvail changed the title (Do not merge)(WIP) Minimal webpack config to build plugin. ROX-29843: Minimal webpack config to build OCP dynamic plugin Jul 17, 2025
@dvail dvail changed the base branch from master to dv/ROX-29846-revert-to-react-router-v5-compat-layer July 17, 2025 18:12
@dvail dvail force-pushed the dv/ROX-29843-ocp-plugin-conf-poc branch from 5aa0b7b to 88618e9 Compare July 18, 2025 17:06
@dvail dvail force-pushed the dv/ROX-29846-revert-to-react-router-v5-compat-layer branch from d25ece2 to 404a6ce Compare July 18, 2025 20:33
@dvail dvail force-pushed the dv/ROX-29846-revert-to-react-router-v5-compat-layer branch from 404a6ce to a3f0366 Compare July 21, 2025 12:33
@dvail dvail force-pushed the dv/ROX-29843-ocp-plugin-conf-poc branch from 88618e9 to 9c07abb Compare July 21, 2025 12:33
@dvail dvail force-pushed the dv/ROX-29846-revert-to-react-router-v5-compat-layer branch from a3f0366 to e952125 Compare July 23, 2025 12:10
@dvail dvail force-pushed the dv/ROX-29843-ocp-plugin-conf-poc branch from 9c07abb to 25da342 Compare July 23, 2025 12:10
Base automatically changed from dv/ROX-29846-revert-to-react-router-v5-compat-layer to master July 23, 2025 19:10
@dvail dvail force-pushed the dv/ROX-29843-ocp-plugin-conf-poc branch from 25da342 to e381ca8 Compare July 23, 2025 19:11
@dvail dvail marked this pull request as ready for review July 23, 2025 19:26
@dvail dvail requested review from a team as code owners July 23, 2025 19:26
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @dvail - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `ui/apps/platform/webpack.ocp-plugin.config.js:5` </location>
<code_context>
+const { ConsoleRemotePlugin } = require('@openshift-console/dynamic-plugin-sdk-webpack');
+const CopyWebpackPlugin = require('copy-webpack-plugin');
+
+const isProd = process.env.NODE_ENV === 'production';
+
+const config = {
</code_context>

<issue_to_address>
Consider splitting the webpack config into common, dev, and prod files and using TsconfigPathsPlugin to simplify and modularize the setup.

You can dramatically cut down on branching, aliases and boilerplate by splitting into a “common/dev/prod” trio and re-using your TS paths via `TsconfigPathsPlugin`. Here’s one way to start:

1. **Install new deps**  
   ```bash
   npm install --save-dev webpack-merge tsconfig-paths-webpack-plugin
   ```

2. **webpack.common.js**  
   ```js
   // webpack.common.js
   const path = require('path');
   const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
   const { ConsoleRemotePlugin } = require('@openshift-console/dynamic-plugin-sdk-webpack');
   const CopyWebpackPlugin = require('copy-webpack-plugin');

   module.exports = {
     context: path.resolve(__dirname, 'src'),
     entry: {},
     resolve: {
       extensions: ['.ts', '.tsx', '.js', '.jsx'],
       plugins: [new TsconfigPathsPlugin({ configFile: './tsconfig.json' })],
     },
     module: {
       rules: [
         {
           test: /\.[jt]sx?$/,
           exclude: /node_modules/,
           use: [{ loader: 'ts-loader', options: { transpileOnly: true } }],
         },
         { test: /\.css$/, use: ['style-loader', 'css-loader'] },
         {
           test: /\.(png|jpe?g|gif|svg|woff2?|ttf|eot|otf)$/,
           type: 'asset/resource',
         },
         { test: /\.m?js$/, resolve: { fullySpecified: false } },
       ],
     },
     plugins: [
       new ConsoleRemotePlugin({
         validateSharedModules: false,
         pluginMetadata: { /* …same metadata… */ },
         extensions: [/* …same extensions… */],
       }),
       new CopyWebpackPlugin({
         patterns: [{ from: 'locales', to: 'locales', noErrorOnMissing: true }],
       }),
     ],
   };
   ```

3. **webpack.dev.js**  
   ```js
   // webpack.dev.js
   const { merge } = require('webpack-merge');
   const common = require('./webpack.common');

   module.exports = merge(common, {
     mode: 'development',
     devtool: 'source-map',
     output: {
       path: path.resolve(__dirname, 'build/static/ocp-plugin'),
       filename: '[name]-bundle.js',
       chunkFilename: '[name]-chunk.js',
     },
     devServer: {
       port: 9001,
       allowedHosts: 'all',
       headers: { 'Access-Control-Allow-Origin': '*' },
       devMiddleware: { publicPath: '/' },
     },
     optimization: { chunkIds: 'named' },
   });
   ```

4. **webpack.prod.js**  
   ```js
   // webpack.prod.js
   const { merge } = require('webpack-merge');
   const common = require('./webpack.common');

   module.exports = merge(common, {
     mode: 'production',
     output: {
       path: path.resolve(__dirname, 'build/static/ocp-plugin'),
       filename: '[name]-bundle-[contenthash].min.js',
       chunkFilename: '[name]-chunk-[contenthash].min.js',
     },
     devtool: false,
     optimization: { minimize: true, chunkIds: 'deterministic' },
   });
   ```

5. **package.json scripts**  
   ```json
   {
     "scripts": {
       "start": "webpack serve --config webpack.dev.js",
       "build": "webpack --config webpack.prod.js"
     }
   }
   ```

This removes all those inline `isProd` checks, you get clean shared rules/plugins, full reuse of your `tsconfig.json` paths, and clear separation of dev/prod concerns.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Jul 24, 2025

@dvail: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/ocp-4-12-nongroovy-e2e-tests 864f29d link false /test ocp-4-12-nongroovy-e2e-tests
ci/prow/ocp-4-19-nongroovy-e2e-tests 864f29d link false /test ocp-4-19-nongroovy-e2e-tests
ci/prow/ocp-4-18-nongroovy-e2e-tests 864f29d link false /test ocp-4-18-nongroovy-e2e-tests

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@dvail dvail merged commit f2680c7 into master Jul 24, 2025
136 of 167 checks passed
@dvail dvail deleted the dv/ROX-29843-ocp-plugin-conf-poc branch July 24, 2025 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants