|
| 1 | += Bundling TinyMCE with an Angular application |
| 2 | +:navtitle: Using a package manager with bundling |
| 3 | +:description: A guide on bundling TinyMCE with an Angular application using Vite. |
| 4 | +:keywords: integration, integrate, angular, bundle, vite, npm, tinymce |
| 5 | +:productSource: package-manager |
| 6 | +:packageName: @tinymce/tinymce-angular |
| 7 | + |
| 8 | +The https://github.com/tinymce/tinymce-angular[Official {productname} Angular component] integrates {productname} into Angular projects. This procedure creates a https://angular.dev/tools/cli/setup-local[basic Angular application] containing a bundled {productname} editor. |
| 9 | + |
| 10 | +For examples of the {productname} Angular integration, visit https://tinymce.github.io/tinymce-angular/[the tinymce-angular storybook]. |
| 11 | + |
| 12 | +== Prerequisites |
| 13 | + |
| 14 | +This procedure requires https://nodejs.org/[Node.js (and NPM)]. |
| 15 | + |
| 16 | +== Procedure |
| 17 | + |
| 18 | +. On a command line or command prompt, install the link:https://angular.dev/tools/cli[Angular CLI Tool] package. |
| 19 | ++ |
| 20 | +[source,sh] |
| 21 | +---- |
| 22 | +npm install -g @angular/cli |
| 23 | +---- |
| 24 | +. Create a new Angular project named `+tinymce-angular-demo+`. |
| 25 | ++ |
| 26 | +[source,sh] |
| 27 | +---- |
| 28 | +ng new --defaults --skip-git tinymce-angular-demo |
| 29 | +---- |
| 30 | +. Change into the newly created directory. |
| 31 | ++ |
| 32 | +[source,sh] |
| 33 | +---- |
| 34 | +cd tinymce-angular-demo |
| 35 | +---- |
| 36 | +. Install the `+tinymce+` and `+@tinymce/tinymce-angular+` packages. |
| 37 | ++ |
| 38 | +[source,sh] |
| 39 | +---- |
| 40 | +npm install tinymce @tinymce/tinymce-angular |
| 41 | +---- |
| 42 | ++ |
| 43 | +include::partial$integrations/premium-plugins-install-step-link.adoc[] |
| 44 | ++ |
| 45 | +[NOTE] |
| 46 | +==== |
| 47 | +For information on configuring premium plugins when bundling, see: xref:bundling-plugins.adoc#using-premium-plugins[Using premium plugins]. |
| 48 | +==== |
| 49 | ++ |
| 50 | +. Using a text editor, create `+src/app/editor.component.ts+` and set the contents to: |
| 51 | ++ |
| 52 | +[source,ts] |
| 53 | +---- |
| 54 | +import { Component } from '@angular/core'; |
| 55 | +import { EditorComponent } from '@tinymce/tinymce-angular'; |
| 56 | +
|
| 57 | +// Ensure you import TinyMCE to register the global variable required by other components |
| 58 | +import 'tinymce/tinymce'; |
| 59 | +// DOM model |
| 60 | +import 'tinymce/models/dom/model'; |
| 61 | +// Theme |
| 62 | +import 'tinymce/themes/silver'; |
| 63 | +// Toolbar icons |
| 64 | +import 'tinymce/icons/default'; |
| 65 | +// Editor styles |
| 66 | +import 'tinymce/skins/ui/oxide/skin.min.css'; |
| 67 | +
|
| 68 | +// Import plugins |
| 69 | +import 'tinymce/plugins/advlist'; |
| 70 | +import 'tinymce/plugins/autolink'; |
| 71 | +import 'tinymce/plugins/link'; |
| 72 | +import 'tinymce/plugins/image'; |
| 73 | +import 'tinymce/plugins/lists'; |
| 74 | +import 'tinymce/plugins/table'; |
| 75 | +import 'tinymce/plugins/code'; |
| 76 | +import 'tinymce/plugins/help'; |
| 77 | +import 'tinymce/plugins/help/js/en.js'; |
| 78 | +import 'tinymce/plugins/wordcount'; |
| 79 | +
|
| 80 | +include::partial$integrations/premium-plugins-bundling.adoc[] |
| 81 | +
|
| 82 | +// Content styles, including inline UI like fake cursors |
| 83 | +import 'tinymce/skins/content/default/content.js'; |
| 84 | +import 'tinymce/skins/ui/oxide/content.js'; |
| 85 | +
|
| 86 | +@Component({ |
| 87 | + selector: 'app-editor', |
| 88 | + standalone: true, |
| 89 | + imports: [EditorComponent], |
| 90 | + template: ` |
| 91 | + <editor |
| 92 | + [init]="init" |
| 93 | + licenseKey="gpl" |
| 94 | + /> |
| 95 | + ` |
| 96 | +}) |
| 97 | +export class MyEditorComponent { |
| 98 | + init: EditorComponent['init'] = { |
| 99 | + height: 500, |
| 100 | + plugins: 'advlist autolink lists link image table code help wordcount', |
| 101 | + toolbar: 'undo redo | blocks | bold italic | alignleft aligncenter alignright | bullist numlist | help' |
| 102 | + }; |
| 103 | +} |
| 104 | +---- |
| 105 | ++ |
| 106 | +. Using a text editor, open `+src/app/app.component.ts+` and update it to use the editor component: |
| 107 | ++ |
| 108 | +[source,ts] |
| 109 | +---- |
| 110 | +import { Component } from '@angular/core'; |
| 111 | +import { MyEditorComponent } from './editor.component'; |
| 112 | +
|
| 113 | +@Component({ |
| 114 | + selector: 'app-root', |
| 115 | + standalone: true, |
| 116 | + imports: [MyEditorComponent], |
| 117 | + template: ` |
| 118 | + <h1>TinyMCE Angular Demo</h1> |
| 119 | + <app-editor /> |
| 120 | + ` |
| 121 | +}) |
| 122 | +export class AppComponent {} |
| 123 | +---- |
| 124 | ++ |
| 125 | +. Run `+ng serve+` to start a dev server |
| 126 | ++ |
| 127 | +[source,sh] |
| 128 | +---- |
| 129 | +ng serve |
| 130 | +---- |
| 131 | ++ |
| 132 | + |
| 133 | +. Build the application for production: |
| 134 | ++ |
| 135 | +[source,sh] |
| 136 | +---- |
| 137 | +ng build |
| 138 | +---- |
| 139 | ++ |
| 140 | +This command creates an optimized production bundle in the `+dist+` directory. |
| 141 | + |
| 142 | +. If premium plugins are included, update the `+licenseKey+` option in the editor component and include your xref:license-key.adoc[License Key]. |
| 143 | + |
| 144 | +== Next Steps |
| 145 | + |
| 146 | +* For information on bundling, see: xref:introduction-to-bundling-tinymce.adoc[] |
| 147 | +* For examples of the {productname} integration, see: https://tinymce.github.io/tinymce-angular/[the tinymce-angular storybook]. |
| 148 | +* For information on customizing: |
| 149 | +** {productname} integration, see: xref:angular-ref.adoc[Angular framework Technical Reference]. |
| 150 | +** {productname}, see: xref:basic-setup.adoc[Basic setup]. |
| 151 | +** The Angular application, see: https://angular.dev[the Angular documentation]. |
| 152 | +* For a complete example, see: https://github.com/tinymce/tinymce-angular-integration-examples/tree/self-hosted-with-npm-premium-plugins[the Angular bundling example repository]. |
0 commit comments