Add Webpack Plugin for PrimeNG
In OneCX version 6 uses PrimeNG 19 and requires applications to add a Webpack plugin. This change is required after upgrading to Angular 19.
|
This setup will be replaced by a OneCX-provided Webpack plugin in a future version. |
Install and Configure the Webpack Plugin
-
Install
modify-source-webpack-pluginnpm install modify-source-webpack-plugin --save-dev -
Import
ModifySourcePluginandReplaceOperationfrommodify-source-webpack-plugininwebpack.config.js -
Create a
modifyPrimeNgPlugininstance with a rules array containing one rule object:-
The rule must define a
testfunction that returnstruewhenmodule.resourceexists and the resource path includesprimeng. -
The rule must include an
operationsarray with aReplaceOperationconfigured with:-
scope:
all -
match pattern:
document\.createElement\(([^)]+)\) -
replacement:
document.createElementFromPrimeNg({"this": this, "arguments": Array.from(arguments), element: $1})
-
-
The rule must also include a
ReplaceOperationconfigured with:-
scope:
all -
match pattern:
Theme.setLoadedStyleName -
replacement:
(function(_){})
-
-
-
Add the
modifyPrimeNgPlugininstance to the Webpackpluginsarray.
const { ModifySourcePlugin, ReplaceOperation } = require('modify-source-webpack-plugin')
...
const modifyPrimeNgPlugin = new ModifySourcePlugin({
rules: [
{
test: (module) => {
return module.resource && module.resource.includes('primeng')
},
operations: [
new ReplaceOperation(
'all',
'document\\.createElement\\(([^)]+)\\)',
'document.createElementFromPrimeNg({"this": this, "arguments": Array.from(arguments), element: $1})'
),
new ReplaceOperation('all', 'Theme.setLoadedStyleName', '(function(_){})')
]
}
]
})
module.exports = {
...webpackConfig,
plugins: [...plugins, modifyPrimeNgPlugin]
}