Search code examples
reactjswebpackcypressrollup

Cypress setup default path aliases


All my Imports use a webpack/rollup default path to import my .js files is under src/.

My project is:

project-name/
    node_modules/
    cypress/
    src/
    ...

Then, when I run test into Cypress I wouldn't have error to import dependencies.

How can I setup a default project forlder for src

Thanks!


Solution

  • Solution:

    cypress/plugins/index.js

    If you are using webpack, add you webpack config into this file.

    const webpack = require('@cypress/webpack-preprocessor');
    
    
    module.exports = (on) => {
      const options = {
    
          webpackOptions: require('../../build/webpack.config'),
          watchOptions: {},
      };
    
      on('file:preprocessor', webpack(options));
    };
    
    // send in the options from your webpack.config.js, so it works the same
    // as your app's code