Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to disable creating CJS dist/index.js file #382

Closed
zhaoyao91 opened this issue Dec 19, 2019 · 2 comments
Closed

Ability to disable creating CJS dist/index.js file #382

zhaoyao91 opened this issue Dec 19, 2019 · 2 comments
Labels
solution: wontfix This will not be worked on solution: workaround available There is a workaround available for this issue topic: multi-entry Related to multi-entry support topic: preserveModules Related to Rollup's preserveModules feature

Comments

@zhaoyao91
Copy link

zhaoyao91 commented Dec 19, 2019

Current Behavior

I have customized the tsdx.config.js as such

// Not transpiled with TypeScript or Babel, so use plain Es6/Node.js!
module.exports = {
  // This function will run for each entry/format/env combination
  rollup(config, options) {
    config.preserveModules = true;
    config.output.file = undefined;
    config.output.dir = `${__dirname}/${config.output.format}`;
    console.log(config);
    return config; // always return a config.
  },
};

Hope it to generate files that match the structure of sources in ${format} dir .

However, there always is a dist/index.js file, which is not desired.

Desired Behavior

Only esm and cjs dirs are generated, no dist dir.

Suggested Solution

Support some customization to allow the pattern of keeping the structure of source files.

Who does this impact? Who is this for?

?

Describe alternatives you've considered

As cjs is not for the future, I may disable generating cjs modules to workaround it for some time. But it is not perfect.

@agilgur5
Copy link
Collaborator

agilgur5 commented Jan 3, 2020

dist/index.js (or something like it) is necessary for determining whether to use dev or prod CJS builds. It is exclusively for CJS, so if you disable CJS, it won't be produced. With multi-entry or preserveModules, it only gets created once though, whereas it should be created for each CJS module.

With #367 you can do something like tsdx build --entry src/**/*.ts and that will create one for each CJS module, but it's not the same as preserveModules as it creates separate bundles for each file. Might be able to add preserveModules on top of the changes in #367 and that might work, but I'm not really sure.

Related to #367, #175 , #276 , #299, and #321 . I believe the example here improves on my workaround for #321 as well, though I haven't tested it myself. Based on all the issues, seems like TSDX should have better support for multi-entry and preserveModules, which are related and may use similar code to achieve, but are not the same.

@agilgur5
Copy link
Collaborator

agilgur5 commented Apr 19, 2020

So as I mentioned in #276 (comment) , the use of preserveModules for CJS causes some issues and I'm not sure it provides any tree-shaking benefits (because it's CJS) either.

preserveModules also isn't meant for creating multiple entries, there is a separate feature for that that is leveraged by #367, and #367 handles creating the dev/prod switch for each entry too.

Going to close this as won't fix because there isn't really a need to disable creating dist/index.js and it is necessary to be able to switch between dev/prod CJS. If you're not using CJS, you don't need to switch between dev/prod CJS, and it won't be generated already.

Support some customization to allow the pattern of keeping the structure of source files.

Please see #276 (comment) for a better tsdx.config.js for preserveModules for ESM. It leverages output.entryFileNames to have similar naming as what TSDX currently has.
#535 creates a flag for this as well that is similar to the tsdx.config.js workaround in that comment but it's still WIP.

@agilgur5 agilgur5 added solution: wontfix This will not be worked on solution: workaround available There is a workaround available for this issue labels Apr 19, 2020
@agilgur5 agilgur5 changed the title Allow disable output dist/index file Disable creating CJS dist/index.js file Apr 19, 2020
@agilgur5 agilgur5 changed the title Disable creating CJS dist/index.js file Ability to disable creating CJS dist/index.js file Apr 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: wontfix This will not be worked on solution: workaround available There is a workaround available for this issue topic: multi-entry Related to multi-entry support topic: preserveModules Related to Rollup's preserveModules feature
Projects
None yet
Development

No branches or pull requests

2 participants