Skip to content

Commit 0412b19

Browse files
authored
Merge pull request #290 from ckeditor/add-umd-build
Feature: Add UMD for better backward compatibility. MINOR BREAKING CHANGE: Replace the default export with named `CKEditorPlugin` export.
2 parents c97c7b2 + 847e776 commit 0412b19

9 files changed

+48
-22
lines changed

demo/demo.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { createApp } from 'vue';
7-
import CKEditorPlugin from '../src/plugin.js';
7+
import { CKEditorPlugin } from '../src/plugin.js';
88
import App from './App.vue';
99

1010
import 'ckeditor5/ckeditor5.css';

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@
1818
"ckeditor 5"
1919
],
2020
"type": "module",
21+
"main": "./dist/ckeditor.umd.cjs",
22+
"module": "./dist/ckeditor.js",
23+
"types": "./dist/plugin.d.ts",
2124
"exports": {
2225
".": {
2326
"types": "./dist/plugin.d.ts",
24-
"import": "./dist/ckeditor.js"
27+
"import": "./dist/ckeditor.js",
28+
"require": "./dist/ckeditor.umd.cjs"
2529
},
2630
"./package.json": "./package.json"
2731
},

src/ckeditor.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import type { Editor, EditorConfig, EventInfo } from 'ckeditor5';
2323
type EditorType = TEditor extends { create( ...args: any[] ): Promise<infer E> } ? E : never;
2424
2525
defineOptions( {
26-
name: 'Ckeditor'
26+
name: 'CKEditor'
2727
} );
2828
2929
const model = defineModel( 'modelValue', { type: String, default: '' } );

src/plugin.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
/* eslint-env browser */
77
import * as Vue from 'vue';
8-
import Ckeditor from './ckeditor.vue';
8+
import CKEditor from './ckeditor.vue';
99

1010
/* istanbul ignore if -- @preserve */
1111
if ( !Vue.version || !Vue.version.startsWith( '3.' ) ) {
@@ -16,24 +16,24 @@ if ( !Vue.version || !Vue.version.startsWith( '3.' ) ) {
1616
);
1717
}
1818

19-
const plugin = {
19+
const CKEditorPlugin = {
2020
/**
2121
* Installs the plugin, registering the `<ckeditor>` component.
2222
*
2323
* @param app The application instance.
2424
*/
2525
install( app: Vue.App ): void {
26-
app.component( 'Ckeditor', Ckeditor );
26+
app.component( 'Ckeditor', CKEditor );
2727
}
2828
};
2929

3030
export {
31-
plugin as default,
32-
Ckeditor
31+
CKEditorPlugin,
32+
CKEditor
3333
};
3434

3535
declare module 'vue' {
3636
interface GlobalComponents {
37-
Ckeditor: typeof Ckeditor;
37+
Ckeditor: typeof CKEditor;
3838
}
3939
}

tests/ckeditor.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { nextTick } from 'vue';
77
import { describe, beforeEach, afterEach, it, expect, vi } from 'vitest';
88
import { mount } from '@vue/test-utils';
9-
import { Ckeditor } from '../src/plugin.ts';
9+
import { CKEditor } from '../src/plugin.ts';
1010
import {
1111
MockEditor,
1212
ModelDocument,
@@ -26,7 +26,7 @@ describe( 'CKEditor component', () => {
2626
} );
2727

2828
it( 'should have a name', () => {
29-
expect( Ckeditor.name ).to.equal( 'Ckeditor' );
29+
expect( CKEditor.name ).to.equal( 'CKEditor' );
3030
} );
3131

3232
it( 'should print a warning if the "window.CKEDITOR_VERSION" variable is not available', async () => {
@@ -251,7 +251,7 @@ describe( 'CKEditor component', () => {
251251

252252
const component = mount( {
253253
components: {
254-
ckeditor: Ckeditor
254+
ckeditor: CKEditor
255255
},
256256
data: () => ( {
257257
editor: MockEditor,
@@ -524,7 +524,7 @@ describe( 'CKEditor component', () => {
524524
} );
525525

526526
function mountComponent( props: Record<string, any> = {} ) {
527-
return mount( Ckeditor, {
527+
return mount( CKEditor, {
528528
props: {
529529
editor: MockEditor,
530530
...props

tests/plugin/integration.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { describe, it, expect, vi } from 'vitest';
77
import { mount } from '@vue/test-utils';
88
import { ClassicEditor, Essentials, Paragraph } from 'ckeditor5';
9-
import CKEditor from '../../src/plugin.js';
9+
import { CKEditorPlugin } from '../../src/plugin.js';
1010

1111
describe( 'CKEditor plugin', () => {
1212
it( 'should work with an actual editor build', async () => {
@@ -40,7 +40,7 @@ describe( 'CKEditor plugin', () => {
4040
{
4141
attachTo: domElement,
4242
global: {
43-
plugins: [ CKEditor ]
43+
plugins: [ CKEditorPlugin ]
4444
},
4545
data: () => ( {
4646
editor: TestEditor,

tests/plugin/localcomponent.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { nextTick } from 'vue';
77
import { describe, it, expect } from 'vitest';
88
import { mount } from '@vue/test-utils';
9-
import { Ckeditor } from '../../src/plugin.js';
9+
import { CKEditor } from '../../src/plugin.js';
1010
import { MockEditor } from '../_utils/mockeditor';
1111

1212
class FooEditor extends MockEditor {}
@@ -15,7 +15,7 @@ describe( 'CKEditor plugin', () => {
1515
it( 'should work when the component is used locally', async () => {
1616
window.CKEDITOR_VERSION = '42.0.0';
1717

18-
const firstComponent = mount( Ckeditor, {
18+
const firstComponent = mount( CKEditor, {
1919
props: {
2020
editor: FooEditor
2121
}

vite.config.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,21 @@ export default defineConfig( {
2525
lib: {
2626
entry: resolve( __dirname, 'src/plugin.ts' ),
2727
name: 'CKEditor',
28-
fileName: 'ckeditor',
29-
formats: [ 'es' ]
28+
fileName: 'ckeditor'
3029
},
3130

3231
rollupOptions: {
3332
external: Object.keys( {
3433
...pkg.dependencies,
3534
...pkg.peerDependencies
36-
} )
35+
} ),
36+
37+
output: {
38+
globals: {
39+
'vue': 'Vue',
40+
'lodash-es': '_'
41+
}
42+
}
3743
}
3844
},
3945

yarn.lock

+18-2
Original file line numberDiff line numberDiff line change
@@ -6635,7 +6635,7 @@ stringify-object@^3.3.0:
66356635
is-obj "^1.0.1"
66366636
is-regexp "^1.0.0"
66376637

6638-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
6638+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
66396639
version "6.0.1"
66406640
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
66416641
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -6649,6 +6649,13 @@ strip-ansi@^5.2.0:
66496649
dependencies:
66506650
ansi-regex "^4.1.0"
66516651

6652+
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
6653+
version "6.0.1"
6654+
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
6655+
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
6656+
dependencies:
6657+
ansi-regex "^5.0.1"
6658+
66526659
strip-ansi@^7.0.1, strip-ansi@^7.1.0:
66536660
version "7.1.0"
66546661
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
@@ -7352,7 +7359,16 @@ wordwrap@^1.0.0:
73527359
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
73537360
integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==
73547361

7355-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", [email protected], wrap-ansi@^6.2.0, wrap-ansi@^7.0.0, wrap-ansi@^8.0.1, wrap-ansi@^8.1.0:
7362+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
7363+
version "7.0.0"
7364+
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
7365+
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
7366+
dependencies:
7367+
ansi-styles "^4.0.0"
7368+
string-width "^4.1.0"
7369+
strip-ansi "^6.0.0"
7370+
7371+
[email protected], wrap-ansi@^6.2.0, wrap-ansi@^7.0.0, wrap-ansi@^8.0.1, wrap-ansi@^8.1.0:
73567372
version "7.0.0"
73577373
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
73587374
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==

0 commit comments

Comments
 (0)