DevExtreme Angular - Using Webpack

NOTE
This tutorial is intended for use with the latest version of Webpack. Compatibility with earlier versions is not guaranteed.

Install DevExtreme

Install the devextreme and devextreme-angular npm packages:

npm install devextreme@23.2 devextreme-angular@23.2 --save --save-exact
NOTE
We recommend saving an exact version of DevExtreme to avoid unexpected updates because DevExtreme does not use Semantic Versioning. In our versioning system, the first and middle numbers indicate a major release which may contain behavior changes.

Configure Webpack Loaders

Open the webpack.config.js file and configure loaders to process CSS and fonts:

webpack.config.js
...
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).

TypeScript
// ...
import 'devextreme/dist/css/dx.light.css';
NOTE
SVG-based UI components do not require theme stylesheets. If you choose to import the stylesheets, the UI components apply an appearance that matches them.

Import DevExtreme Modules

Go to the NgModule in which you are going to use DevExtreme UI components and import the required DevExtreme modules. Note that if tree shaking is configured in your application, you can import the modules from devextreme-angular. Otherwise, you should import them from specific files.

app.module.ts
// ...
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:

app.component.html
app.component.ts
<dx-button
    text="Click me"
    (onClick)="helloWorld()">
</dx-button>
import { Component } from '@angular/core';

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
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.

Demos and Code Examples

Refer to the following resources for code samples and usage examples: