DevExtreme Angular - Using Webpack
Install DevExtreme
Install the devextreme and devextreme-angular npm packages:
npm install devextreme@25.2 devextreme-angular@25.2 --save --save-exact
Configure Webpack Loaders
Open the webpack.config.js file and configure loaders to process CSS and fonts:
...
rules: [
...
{
test: /\.css$/,
use: [
{ loader: "style-loader" },
{ loader: "css-loader" }]
}
]
...In addition, open the package.json file and ensure style-loader, css-loader, and url-loader are listed in devDependencies.
Import Stylesheets
Open the main .ts file and import a predefined theme stylesheet (dx.light.css in the code below).
// ... import 'devextreme/dist/css/dx.light.css';
Import DevExtreme Modules
DevExtreme components are standalone. Import them as follows:
import { Component } from '@angular/core';
import { DxButtonComponent } from 'devextreme-angular/ui/button';
@Component({
selector: 'app-root',
standalone: true,
imports: [DxButtonComponent],
templateUrl: './app.component.html',
styleUrl: './app.component.css'
})
export class AppComponent { }The nested components should also be imported. For example, the following code snippet imports DataGrid, its columns, sorting, and a template.
*dxTemplate, import DxTemplateDirective.
import { Component } from '@angular/core';
import { DxTemplateDirective } from 'devextreme-angular';
import { DxDataGridComponent, DxiDataGridColumnComponent } from 'devextreme-angular/ui/data-grid';
@Component({
selector: 'app-root',
standalone: true,
imports: [DxDataGridComponent, DxiDataGridColumnComponent, DxTemplateDirective],
templateUrl: './app.component.html',
styleUrl: './app.component.css'
})
export class AppComponent { }
<dx-data-grid>
<dxo-data-grid-sorting mode="none"></dxo-data-grid-sorting>
<dxi-data-grid-column dataField="date"></dxi-data-grid-column>
<dxi-data-grid-column
caption="Employee"
cellTemplate="employeeTemplate"
></dxi-data-grid-column>
<div *dxTemplate="let data of 'employeeTemplate'">
<img
[src]="data.value"
alt="Picture of {{ data.data.FirstName }} {{ data.data.LastName }}"
/>
</div>
</dx-data-grid>Modules facilitate working with multiple configuration components. You can import them as follows:
import { Component } from '@angular/core';
import { DxDataGridModule } from 'devextreme-angular';
@Component({
selector: 'app-root',
standalone: true,
imports: [DxDataGridModule],
templateUrl: './app.component.html',
styleUrl: './app.component.css'
})
export class AppComponent { }If you use NgModule, import the DevExtreme modules as demonstrated in the following code snippet. If tree shaking is configured in your application, import the modules from devextreme-angular. If not, import them from files.
// ...
import { DxButtonModule } from 'devextreme-angular';
// or if tree shaking is not configured
// import { DxButtonModule } from 'devextreme-angular/ui/button';
@NgModule({
imports: [
// ...
DxButtonModule
],
// ...
})
export class AppModule { }Now you can use the DevExtreme UI component in your application:
<dx-button
text="Click me"
(onClick)="helloWorld()">
</dx-button>
// ...
export class AppComponent {
helloWorld() {
alert('Hello world!');
}
}Run the Application
Build the application with the following command:
webpack
... and open the HTML file where your bundle is referenced (usually index.html) in your browser.
If you have technical questions, please create a support ticket in the DevExpress Support Center.