bahmutov / add-typescript-to-cypress

Quickly adds TypeScript spec support to Cypress
https://github.com/bahmutov/test-add-typescript-to-cypress
107 stars 6 forks source link

Can we use path aliases with TypeScript #40

Closed bahmutov closed 5 years ago

bahmutov commented 5 years ago

like this example https://dev.to/lars124/path-aliases-with-typescript-in-nodejs-4353

instead of this

import { User } from '../../user/model';
import { Article } from '../../article/model';

import { Cache } from '../../../../cache';
import { MongoDB } from '../../../../mongodb';

you can use

import { User } from '@modules/user/model';
import { Article } from '@modules/article/model';

import { Cache } from '@services/cache';
import { MongoDB } from '@services/mongodb';
bahmutov commented 5 years ago

Yes, just need to pretty much duplicate this information in the plugin to provide https://webpack.js.org/configuration/resolve/#resolvealias

resolve: {
  ....
  alias: {
    '@utils': path.resolve(__dirname, '../e2e/cypress/integration/utils/')
  }
}
bahmutov commented 5 years ago

wrote a blog post about it Using TypeScript aliases in Cypress tests