A CLI tool for scaffolding and generating custom components for DataFlex webapps. Write modern JavaScript classes, bundle them with Vite, and have them available in your DataFlex application.
- Modern JavaScript — write ES2024 class syntax with full ESLint checking
- Vite bundler — fast builds, watch mode for development
- IIFE output — components are bundled into
AppHtml/Custom/DFCC.jsand loaded as a global namespace object - Multiple components — all components share a single bundle
- Per-component CSS — each component gets its own stylesheet
Install NodeJS if you haven't already:
winget install OpenJS.NodeJS.LTS
Navigate to your DataFlex project folder and run:
npx df-cc init
This creates the build setup in the current directory:
package.json— Vite + ESLint dependencies and build scriptsvite.config.js— Vite IIFE bundle configurationeslint.config.js— ESLint 10 flat configsrc/index.js— entry point that exports all components
Dependencies are installed automatically.
Options:
npx df-cc init --name MyApp
Use --name to set the global namespace (default: DFCC). All components will be available as
window.MyApp.<ComponentName> in the browser.
npx df-cc create MyCustomComponent
This generates:
src/MyCustomComponent.js— JavaScript class extendingdf.WebBaseControlsrc/MyCustomComponent.css— stylesheet for the componentAppSrc/cMyCustomComponent.pkg— DataFlex class withpsJSClasspre-set
And updates src/index.js to export the new component.
Run create again for each additional component you want in the bundle:
npx df-cc create MyOtherComponent
Build for production (runs ESLint first):
npm run build
Watch mode during development (rebuilds on file changes):
npm run watch
Add the bundled files to your Index.html:
<script src="Custom/DFCC.js"></script>
<link rel="stylesheet" href="Custom/DFCC.css">In your DataFlex program, use the generated .pkg file like any other web control:
Use AppSrc\cMyCustomComponent.pkg
Object oMyWidget is a cMyCustomComponent
End_Object
Each JavaScript component class is exported by name from src/index.js.
Vite bundles everything as an IIFE and assigns the exports to a global namespace object (e.g. window.DFCC).
The DataFlex psJSClass property points to the class using dot notation, e.g. "DFCC.MyCustomComponent".
The generated JavaScript class template looks like this:
export class MyCustomComponent extends df.WebBaseControl {
constructor(sName, oParent) {
super(sName, oParent);
this._sControlClass = 'my-custom-component';
}
openHtml(aHtml) {
super.openHtml(aHtml);
aHtml.push(`<div class="my-custom-component-wrapper" id="${this._sControlId}">`);
aHtml.push('<h1>Hello DataFlex!</h1>');
aHtml.push('</div>');
}
afterRender() {
this._eControl = df.dom.query(this._eElem, `#${this._sControlId}`);
super.afterRender();
}
}You can install and use npm packages inside your component files. They will be included in the bundle automatically.
MIT