diff --git a/README.MD b/README.MD index 7acfd9f..b08a910 100644 --- a/README.MD +++ b/README.MD @@ -61,9 +61,9 @@ npm install http://xxxx/npm/haina-npm-0.1.0.tgz // import { commons, request, utils, hooks } from '@haina/npm'; // Import only common utilities -import { isEmpty } from '@haina/npm/build/esm/utils/commons.js'; +import { isEmpty } from '@haina/npm/esm/utils/commons.js'; // Import only request utilities -import { fetchJSON } from '@haina/npm/build/esm/utils/request.js'; +import { fetchJSON } from '@haina/npm/esm/utils/request.js'; ``` ### 安装单个模块 diff --git a/scripts/pack-modules.js b/scripts/pack-modules.js index 66df458..02103b5 100644 --- a/scripts/pack-modules.js +++ b/scripts/pack-modules.js @@ -75,7 +75,15 @@ function packDirectory(dirName, dirPath) { description: `Haina ${dirName} module - part of @haina/npm utility library`, main: `build/cjs/${dirName}/index.js`, // Assuming there's an index.js in the directory module: `build/esm/${dirName}/index.js`, - type: 'module', + exports: { + ".": { + "import": `./build/esm/${dirName}/index.js`, + "require": `./build/cjs/${dirName}/index.js`, + }, + "./esm/*": "./build/esm/*", + "./cjs/*": "./build/cjs/*" + }, + // type: 'module', files: [ "build" ], @@ -146,7 +154,13 @@ function packIndividualFile(fileName, parentDir, parentPath) { description: `Haina ${parentDir}-${moduleName} module - part of @haina/npm utility library`, main: parentDir === 'src' ? `build/cjs/${fileName}` : `build/cjs/${parentDir}/${fileName}`, module: parentDir === 'src' ? `build/esm/${fileName}` : `build/esm/${parentDir}/${fileName}`, - type: 'module', + exports: { + ".": { + "import": parentDir === 'src' ? `./build/esm/${fileName}` : `./build/esm/${parentDir}/${fileName}`, + "require": parentDir === 'src' ? `./build/cjs/${fileName}` : `./build/cjs/${parentDir}/${fileName}` + } + }, + // type: 'module', files: [ "build" ],