I'm working with a multi entry point app, It heavily using common components and I loaded it from resolve section in webpack (see webpack file)
webpack file
resolve: {
extensions: ['', '.js', '.css', '.scss', '.jsx', '.json'],
modulesDirectories: ['node_modules', 'common']
}
But issue is when I'm going to test that component it can't load directories from common folder, because I didn't defined it as module directory, So Is there a way to load custom modules Directories in test environment
I solved it, we can define custom module path with using app-module-path
package
install
npm install app-module-path --save
require in your file, before any require() calls:
require('app-module-path').addPath(process.env.PWD + '/common');
then you can import your component from /common/util/Base
import Base from 'util/Base';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.