Skip to content

Commit 88033b6

Browse files
committed
remove the DOCSIFY global made by Rollup, and move Docsify into a separate file where we can import it from tests while leaving the entry point for the bundle without any exports so that Rollup will not create a global variable from it
1 parent 1b8a81a commit 88033b6

File tree

4 files changed

+26
-49
lines changed

4 files changed

+26
-49
lines changed

build/build.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,12 @@ async function buildCore() {
5050
promises.push(build({
5151
input: 'src/core/index.js',
5252
output: 'docsify.js',
53-
globalName: 'DOCSIFY'
5453
}))
5554

5655
if (isProd) {
5756
promises.push(build({
5857
input: 'src/core/index.js',
5958
output: 'docsify.min.js',
60-
globalName: 'DOCSIFY',
6159
plugins: [uglify()]
6260
}))
6361
}

src/core/Docsify.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { initMixin } from './init';
2+
import { routerMixin } from './router';
3+
import { renderMixin } from './render';
4+
import { fetchMixin } from './fetch';
5+
import { eventMixin } from './event';
6+
import initGlobalAPI from './global-api';
7+
8+
export function Docsify() {
9+
this._init();
10+
}
11+
12+
const proto = Docsify.prototype;
13+
14+
initMixin(proto);
15+
routerMixin(proto);
16+
renderMixin(proto);
17+
fetchMixin(proto);
18+
eventMixin(proto);
19+
20+
/**
21+
* Global API
22+
*/
23+
initGlobalAPI();

src/core/index.js

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,5 @@
1-
import Prism from 'prismjs';
2-
import marked from 'marked';
3-
import { initMixin } from './init';
4-
import { routerMixin } from './router';
5-
import { renderMixin } from './render';
6-
import { fetchMixin } from './fetch';
7-
import { eventMixin } from './event';
8-
import initGlobalAPI from './global-api';
9-
import { Compiler as DocsifyCompiler } from './render/compiler';
10-
import * as util from './util';
111
import * as dom from './util/dom';
12-
import { slugify } from './render/slugify';
13-
import { get } from './fetch/ajax';
14-
15-
export function Docsify() {
16-
this._init();
17-
}
18-
19-
const proto = Docsify.prototype;
20-
21-
initMixin(proto);
22-
routerMixin(proto);
23-
renderMixin(proto);
24-
fetchMixin(proto);
25-
eventMixin(proto);
26-
27-
/**
28-
* Global API
29-
*/
30-
initGlobalAPI(); // deprecated
31-
32-
// Rollup assigns all exports from this file onto a single DOCSIFY global.
33-
export { util, dom, get, slugify, DocsifyCompiler, marked, Prism };
34-
export const version = '__VERSION__';
2+
import { Docsify } from './Docsify';
353

364
/**
375
* Run Docsify

test/unit/docsify.test.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,6 @@ describe('Docsify public API', () => {
6868
expect(typeof DOM.window.DocsifyCompiler).to.equal('function');
6969
expect(typeof DOM.window.marked).to.equal('function');
7070
expect(typeof DOM.window.Prism).to.equal('object');
71-
72-
// new global API, everything under one namespace (DOCSIFY)
73-
expect(typeof DOM.window.DOCSIFY).to.equal('object');
74-
expect(typeof DOM.window.DOCSIFY.Docsify).to.equal('function');
75-
expect(typeof DOM.window.DOCSIFY.util).to.equal('object');
76-
expect(typeof DOM.window.DOCSIFY.dom).to.equal('object');
77-
expect(typeof DOM.window.DOCSIFY.get).to.equal('function');
78-
expect(typeof DOM.window.DOCSIFY.slugify).to.equal('function');
79-
expect(typeof DOM.window.DOCSIFY.version).to.equal('string');
80-
expect(typeof DOM.window.DOCSIFY.DocsifyCompiler).to.equal('function');
81-
expect(typeof DOM.window.DOCSIFY.marked).to.equal('function');
82-
expect(typeof DOM.window.DOCSIFY.Prism).to.equal('object');
8371
});
8472

8573
describe('Docsify config function', function() {
@@ -102,7 +90,7 @@ describe('Docsify public API', () => {
10290
};
10391

10492
const { documentReady } = require('../../src/core/util/dom');
105-
const { Docsify } = require('../../src/core/index');
93+
const { Docsify } = require('../../src/core/Docsify');
10694
await new Promise(resolve => documentReady(resolve));
10795

10896
new Docsify(); // eslint-disable-line
@@ -136,7 +124,7 @@ describe('Docsify public API', () => {
136124
};
137125

138126
const { documentReady } = require('../../src/core/util/dom');
139-
const { Docsify } = require('../../src/core/index');
127+
const { Docsify } = require('../../src/core/Docsify');
140128
await new Promise(resolve => documentReady(resolve));
141129

142130
new Docsify(); // eslint-disable-line

0 commit comments

Comments
 (0)