-
Notifications
You must be signed in to change notification settings - Fork 1
GenerateWebresource
Niels Steenbeek edited this page Mar 17, 2023
·
5 revisions
hso-d365 generate Webresource [name] [--template Template]
# Type Template: 'React' | 'HTML'
CLI Command 'generate Webresource [name]' generates a Webresource. Via a prompt a template can be choosen:
- HTML
- React
An entry will be added for the webpack.config.js file.
Following files will be generated:
- src/[name]/[name].html
- src/[name]/[name].scss
- src/[name]/[name].ts
This is the root file. The onLoad function is the starting point for the code. The Xrm.GlobalContext is passed as parameter.
import './[name].scss';
class [name] {
public static onLoad(globalContext: Xrm.GlobalContext): void {
// code here
}
}
export function onLoad(): void {
const globalContext = Xrm.Utility.getGlobalContext();
Webresource.onLoad(globalContext);
}
React template [name].ts using State hook
import ReactDom from 'react-dom';
import './[name].scss';
import {Translation} from '../translation/Translation';
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface [name]Props {}
// eslint-disable-next-line no-unused-vars,max-lines-per-function
const [name]: React.FC<WebresourceProps> = (props: [name]Props): JSX.Element => {
const [testBoolean, setTestBoolean] = useState(false);
// eslint-disable-next-line max-lines-per-function
return (
<>
<span>{Translation.translate('Language')}</span>
</>
);
};
export default [name];
export function onLoad(): void {
const rootDiv = document.getElementById('[name]');
ReactDom.render(<[name]/>, rootDiv);
}
Use command
hso-d365 generate Webresource --help