7
4

More than 5 years have passed since last update.

nuxt + TypeScriptで、process.client, process.serverを定義する

Posted at

nuxt2.1.0, node10.11.0
2018.10.19現在


nuxtではnodeの環境変数processを拡張する形で、process.server, process.clientが設定されている。

TypeScriptで使う場合は定義も拡張しないとプロパティが存在しないよエラーになるので、適当に拡張する

some.d.ts

// processは'NodeJS.Process'で定義されてる
declare namespace NodeJS {
  interface Process {
    server: boolean;
    browser: boolean;
  }
}
7
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4