diff --git a/src/Derby.ts b/src/Derby.ts index dba575f0..8abfc673 100644 --- a/src/Derby.ts +++ b/src/Derby.ts @@ -26,6 +26,14 @@ export class Derby extends DerbyBase { createApp(name: string, filename: string, options) { return new this.App(this, name, filename, options); } + + use(plugin, options) { + return racer.util.use.call(this, plugin, options); + } + + serverUse(plugin, options) { + return racer.util.serverUse.call(this, plugin, options); + } } if (!racer.util.isServer) { diff --git a/src/DerbyForServer.ts b/src/DerbyForServer.ts new file mode 100644 index 00000000..417a3789 --- /dev/null +++ b/src/DerbyForServer.ts @@ -0,0 +1,13 @@ +import { AppBase } from './App'; +import { AppForServer } from './AppForServer'; +import { DerbyBase } from './Derby'; +import { PageForServer } from './PageForServer'; + +export class DerbyForServer extends DerbyBase { + App: typeof AppForServer = AppForServer; + Page: typeof PageForServer = PageForServer; + + createApp(name: string, filename: string, options: any): AppBase { + return new this.App(this, name, filename, options); + } +} diff --git a/src/index.ts b/src/index.ts index 0baf5b8a..ca44af63 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,35 +1,9 @@ -import { util } from 'racer'; +import { Derby } from './Derby'; -import { AppBase as AppClass, type App } from './App'; -import { type AppForServer } from './AppForServer'; -import { PageBase as PageClass } from './Page'; - -/* eslint-disable @typescript-eslint/no-var-requires */ -if (util.isServer) { - // @ts-expect-error Required tomfoolery for isomorphic things - AppClass = require('./App').App; - // @ts-expect-error Required tomfoolery for isomorphic things - PageClass = require('./Page').Page; -} else { - // @ts-expect-error Required tomfoolery for isomorphic things - AppClass = require('./AppForServer').AppForServer; - // @ts-expect-error Required tomfoolery for isomorphic things - PageClass = require('./PageForServer').PageForServer; -} -/* eslint-enable @typescript-eslint/no-var-requires */ - -export { Component } from './components'; -export { AppClass as App }; -export { PageClass as Page }; -export { type PageParams, type QueryParams } from './routes'; -export { Dom } from './Dom'; -export { util }; - -export function createApp(name: string, filename: string, options) { - if (util.isServer) { - return new (AppClass as unknown as typeof AppForServer)({ Page: PageClass }, name, filename, options); - } else { - return new (AppClass as unknown as typeof App)({ Page: PageClass }, name, filename, options); - } -} +// eslint-disable-next-line @typescript-eslint/no-var-requires +const util = require('racer').util; +const DerbyClass = util.isServer + ? util.serverRequire(module, './DerbyForServer').DerbyForServer + : Derby; +export = new DerbyClass(); diff --git a/tsconfig.json b/tsconfig.json index 6570fab6..ba98083a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,9 +7,9 @@ "noImplicitUseStrict": true, "outDir": "dist", "target": "ES5", - "sourceMap": true, - "declaration": true, - "declarationMap": true, + "sourceMap": false, + "declaration": false, + "declarationMap": false, }, "include": [ "src/**/*"