💬

モジュールimport時に絶対パスで記述したい

2023/10/21に公開

モジュールimport時に絶対パスで記述したい

Sails.jsでweebpackを使う場合の設定

Can I override this hook to use a different asset pipeline like Gulp or Webpack?
Yes. To override this hook, define your replacement hook under your app's api/hooks/ directory. Or, to share your override with the world, publish it on NPM (e.g. @mynpmusername/sails-hook-grunt or sails-hook-webpack). Just be sure to include the following in your package.json:

"sails": {
  "isHook": true,
  "hookName": "grunt"
}

参考

tsconfig.jsonの設定

{
  "compilerOptions": {
    "baseUrl": "./api",
    "paths": {
      "@/*": ["./*"]
    },
  }
}

参考

ts-nodeでのパスの解決

tsconfig-pathsをインストールして、
実行時にts-node -r tsconfig-paths/register ./server/index.ts

参考

requireでの呼び方

require('ts-node').register({ /* options */ })

参考

ESLintのエイリアス対応

eslint-import-resolver-aliasをインストール

.eslintrc.json

"settings": {
  "import/resolver": {
    "alias": {
      "map": [
        ["@/*", "./*"]
      ],
      "extensions": [".ts", ".js", ".json"]
    }
  }
},

参考

Discussion