Skip to content

Commit

Permalink
revert(dev): フロントエンド・バックエンドを分離する開発モードを廃止
Browse files Browse the repository at this point in the history
(cherry picked from commit 35104d8)

Co-authored-by: かっこかり <[email protected]>
Co-authored-by: syuilo <[email protected]>
  • Loading branch information
3 people committed Jan 25, 2025
1 parent eda6d6f commit d185994
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 240 deletions.
19 changes: 2 additions & 17 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,10 @@ pnpm dev
command.

- Server-side source files and automatically builds them if they are modified. Automatically start the server process(es).
- Vite HMR (just the `vite` command) is available. The behavior may be different from production.
- Service Worker is watched by esbuild.
- The front end can be viewed by accessing `http://localhost:5173`.
- The backend listens on the port configured with `port` in .config/default.yml.
If you have not changed it from the default, it will be "http://localhost:3000".
If "port" in .config/default.yml is set to something other than 3000, you need to change the proxy settings in packages/frontend/vite.config.local-dev.ts.

### `MK_DEV_PREFER=backend pnpm dev`
pnpm dev has another mode with `MK_DEV_PREFER=backend`.

```
MK_DEV_PREFER=backend pnpm dev
```

- This mode is closer to the production environment than the default mode.
- Vite runs behind the backend (the backend will proxy Vite at /vite).
- Vite HMR (just the `vite` command) is available. The behavior may be different from production.
- Vite runs behind the backend (the backend will proxy Vite at /vite except for websocket used for HMR).
- You can see Misskey by accessing `http://localhost:3000` (Replace `3000` with the port configured with `port` in .config/default.yml).
- To change the port of Vite, specify with `VITE_PORT` environment variable.
- HMR may not work in some environments such as Windows.

### Dev Container
Instead of running `pnpm` locally, you can use Dev Container to set up your development environment.
Expand Down
5 changes: 4 additions & 1 deletion packages/backend/src/server/web/ClientServerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,12 @@ export class ClientServerService {
done();
});
} else {
const configUrl = new URL(this.config.url);
const urlOriginWithoutPort = configUrl.origin.replace(/:\d+$/, '');

const port = (process.env.VITE_PORT ?? '5173');
fastify.register(fastifyProxy, {
upstream: 'http://localhost:' + port,
upstream: urlOriginWithoutPort + ':' + port,
prefix: '/vite',
rewritePrefix: '/vite',
});
Expand Down
1 change: 0 additions & 1 deletion packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"type": "module",
"scripts": {
"watch": "vite",
"dev": "vite --config vite.config.local-dev.ts --debug hmr",
"build": "vite build",
"storybook-dev": "nodemon --verbose --watch src --ext \"mdx,ts,vue\" --ignore \"*.stories.ts\" --exec \"pnpm build-storybook-pre && pnpm exec storybook dev -p 6006 --ci\"",
"build-storybook-pre": "(tsc -p .storybook || echo done.) && node .storybook/generate.js && node .storybook/preload-locale.js && node .storybook/preload-theme.js",
Expand Down
95 changes: 0 additions & 95 deletions packages/frontend/src/_dev_boot_.ts

This file was deleted.

36 changes: 0 additions & 36 deletions packages/frontend/src/index.html

This file was deleted.

1 change: 1 addition & 0 deletions packages/frontend/src/pages/welcome.entrance.a.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function getInstanceIcon(instance: Misskey.entities.FederationInstance): string
if (!instance.iconUrl) {
return '';
}

return getProxiedImageUrl(instance.iconUrl, 'preview');
}

Expand Down
89 changes: 0 additions & 89 deletions packages/frontend/vite.config.local-dev.ts

This file was deleted.

6 changes: 6 additions & 0 deletions packages/frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import pluginReplace from '@rollup/plugin-replace';
import pluginVue from '@vitejs/plugin-vue';
import typescript from '@rollup/plugin-typescript';
import { type UserConfig, defineConfig } from 'vite';
import * as yaml from 'js-yaml';
import { promises as fsp } from 'fs';

import locales from '../../locales/index.js';
import meta from '../../package.json';
import packageInfo from './package.json' with { type: 'json' };
import pluginUnwindCssModuleClassName from './lib/rollup-plugin-unwind-css-module-class-name.js';
import pluginJson5 from './vite.json5.js';

const url = process.env.NODE_ENV === 'development' ? yaml.load(await fsp.readFile('../../.config/default.yml', 'utf-8')).url : null;
const host = url ? (new URL(url)).hostname : undefined;

const extensions = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.json', '.json5', '.svg', '.sass', '.scss', '.css', '.vue'];

/**
Expand Down Expand Up @@ -65,6 +70,7 @@ export function getConfig(): UserConfig {
base: '/vite/',

server: {
host,
port: 5173,
},

Expand Down
2 changes: 1 addition & 1 deletion scripts/dev.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ execa('pnpm', ['--filter', 'backend', 'dev'], {
stderr: process.stderr,
});

execa('pnpm', ['--filter', 'frontend', process.env.MK_DEV_PREFER === 'backend' ? 'watch' : 'dev'], {
execa('pnpm', ['--filter', 'frontend', 'watch'], {
cwd: _dirname + '/../',
stdout: process.stdout,
stderr: process.stderr,
Expand Down

0 comments on commit d185994

Please sign in to comment.