How to introduce the module according to the subpath

see that many common modules can be introduced through subpaths, such as ant-desin :

const AdaBoost = require("mlhelper/algorithm/AdaBoost");

//or
import AdaBoost from "mlhelper/algorithm/AdaBoost";

report the error of module not found directly.

what can I do to achieve this kind of on-demand loading?


is something like this: https://github.com/Jiasm/tetr.

create a separate index.js file as an index, in which other module can be introduced.

a.js
 

you need to package multiple files instead of a single bundle file. mlhelper/algorithm/AdaBoost will be parsed to node_modules/mlhelper/algorithm/AdaBoost obviously there is no algorithm directory in your mlhelper package. You can require ('mlhelper/src/algorithm/AdaBoost') provided that your environment is configured to compile the ts content in node_modules.

you need to configure tsconfig.json to compile each file of your src to another lib directory.

Menu