Skip to content

Commit

Permalink
fix: writeCJSMain plugin - emit index file
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Nov 10, 2021
1 parent d55257d commit 6dcbe62
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions vx/config/rollup/plugins/writeCJSMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@ module.exports = writeCJSMain;
function writeCJSMain({ isMain, rootPath }) {
return {
name: 'write-cjs-main',
writeBundle: once(({ name, ...opts }) => {
let mainPath = rootPath;
writeBundle: once(({ name }) => {
let exportPath = rootPath;

if (!isMain) {
mainPath = path.join(mainPath, name);
fse.ensureDirSync(mainPath);

exportPath = path.join(exportPath, name);
fse.ensureDirSync(exportPath);
fse.writeJSONSync(
path.join(mainPath, 'package.json'),
path.join(exportPath, 'package.json'),
packageJson(name)
);
}

fse.writeFileSync(
path.resolve(mainPath, opts.fileNames.MAIN_EXPORT),
path.resolve(exportPath, opts.fileNames.MAIN_EXPORT),
genEntry(name, isMain),
'utf8'
);
Expand All @@ -48,7 +47,7 @@ if (process.env.NODE_ENV === '${opts.env.PRODUCTION}') {

function packageJson(name) {
return {
main: `./index.js`,
main: `./${opts.fileNames.MAIN_EXPORT}`,
name,
private: true,
types: `../types/${name}.d.ts`,
Expand Down

0 comments on commit 6dcbe62

Please sign in to comment.