Skip to content

Commit

Permalink
fix: fix extra file being build with spa target
Browse files Browse the repository at this point in the history
  • Loading branch information
liximomo committed Jun 19, 2020
1 parent 8dd2139 commit 5a6bb13
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 21 deletions.
5 changes: 5 additions & 0 deletions packages/app/core/application-spa-server.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Runtime } from '@shuvi/types';

import IApplicationModule = Runtime.IApplicationModule;

export const create: IApplicationModule['create'];
26 changes: 22 additions & 4 deletions packages/core/src/app/components/ApplicationFile.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React from 'react';
import { observer } from 'mobx-react';
import { File } from '@shuvi/react-fs';

function ApplicationFile() {
const template = `
const app = `
import AppComponent from "@shuvi/app/core/app";
import routes from "@shuvi/app/core/routes";
import { Application } from "@shuvi/runtime-core/lib/lib/application";
Expand Down Expand Up @@ -42,7 +41,26 @@ if (module.hot) {
}
`;

return <File name="application.js" content={template} />;
const emptyApp = `
import { Application } from "@shuvi/runtime-core/lib/lib/application";
export function create(context, options) {
return new Application({
AppComponent: null,
routes: [],
context,
render: options.render
});
return app;
}
`;

return (
<>
<File name="application.js" content={app} />
<File name="application-spa-server.js" content={emptyApp} />
</>
);
}

export default observer(ApplicationFile);
export default ApplicationFile;
21 changes: 21 additions & 0 deletions packages/react-fs/src/__tests__/renderer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,26 @@ describe('renderer', () => {
const files = await recursiveReadDir('/');
expect(files).toEqual(['a/a1', 'a/a2']);
});

test('shuold support fragment in dir', async () => {
const Child = () => (
<>
<File name="b1" content="test" />
<File name="b2" content="test" />
</>
);
await renderOnce(
<>
<File name="a" content="test" />
<Dir name="b">
<Child />
</Dir>
</>,
'/'
);

const files = await recursiveReadDir('/');
expect(files).toEqual(['a', 'b/b1', 'b/b2']);
});
});
});
4 changes: 2 additions & 2 deletions packages/runtime-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ loadRouteComponent(() => import(/* webpackChunkName: "page-${route.id}" */"${com
}

if (history === 'hash') {
return resolveDist('bootstrap.hash');
return resolveDist('clientRender.hash');
}

return resolveDist('bootstrap.browser');
return resolveDist('clientRender.browser');
}

getAppModulePath(): string {
Expand Down
39 changes: 24 additions & 15 deletions packages/shuvi/src/api/setupApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,31 @@ export async function setupApp(api: Api) {

api.addAppFile(
File.module('server.js', {
exports: {
[api.resolveAppFile('core', 'document')]: {
imported: '*',
local: 'document'
},
[api.resolveAppFile('core', 'application')]: {
imported: '*',
local: 'application'
},
...(api.config.ssr && {
[runtime.getServerRendererModulePath()]: {
imported: 'default',
local: 'renderer'
exports: api.config.ssr
? {
[api.resolveAppFile('core', 'document')]: {
imported: '*',
local: 'document'
},
[api.resolveAppFile('core', 'application')]: {
imported: '*',
local: 'application'
},
[runtime.getServerRendererModulePath()]: {
imported: 'default',
local: 'renderer'
}
}
: {
[api.resolveAppFile('core', 'document')]: {
imported: '*',
local: 'document'
},
[api.resolveAppFile('core', 'application-spa-server')]: {
imported: '*',
local: 'application'
}
}
})
}
})
);

Expand Down

0 comments on commit 5a6bb13

Please sign in to comment.