question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple entries to output multiple build files

See original GitHub issue

Current Behavior

When building source with multiple entries, using --entry src/**.ts the build only uses the source of the first file it finds as the main entry point for ESM and CJS output.

Desired Behavior

It would be nice to be able to specify multiple destinations for different source files from a single codebase.

Suggested Solution

A solution could be to change the behavior of --entry flag, so that instead of outputting only definition files from multiple sources, it should output entry points for each specified entry file.

For example, with a folder structure like this:

src/
  code.ts
  ui.ts

Running tsdx build --entry src/**.ts or --entry src/code.ts src/ui.ts will yield the following output files:

dist/
  code.js
  code.cjs.production.js
  code.cjs.development.js
  code.esm.js
  ui.js
  ui.cjs.production.js
  ui.cjs.development.js
  ui.esm.js

Where code.js and ui.js are similar to index.js for single entry projects.

Who does this impact? Who is this for?

This is useful for building applications, plugins or other types of projects, where multiple entries are required, without having to create a monolithic repo architecture with a custom build process to combine build files.

An example is the recently released Figma Plugin API, which specifies a main file for the underlying plugin code, and a ui file for browser UI part.

See an example project using React and Webpack to create a Figma UI plugin

Describe alternatives you’ve considered

  • Creating a monorepo and using a custom script to merge the builds into a single folder.
  • Move to a custom setup with webpack that allows for this type of configuration.

Additional context

I was looking for ways to specify multiple entries with --entry as outlined in https://github.com/palmerhq/tsdx/pull/28 but it seems to only output source files for the first file it finds and the rest just outputs as definition files, not actual source files. This is a bit confusing and may be a bug as it shares the same property name as webpack (entry), but works differently.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:75
  • Comments:19 (6 by maintainers)

github_iconTop GitHub Comments

9reactions
yordiscommented, Nov 3, 2019

Related to this I guess,

How could I avoid having one single outputted file for ESM build?

src/
  folder/
    file.ts
  code.ts
  ui.ts
dist/
  folder/
    file.js
  code.js
  ui.js

I am looking for having something like Material UI folks put together, so it is more ESM friendly by default.

8reactions
jaredpalmercommented, Sep 28, 2019

Yep. This should be easy to implement just have to fool around with the cjs entry generation so it does it multiple times

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create multiple output paths in Webpack config
Webpack does support multiple output paths. Set the output paths as the entry key. And use the name as output template. webpack config:...
Read more >
Multiple Outputs (automake)
Suppose we have a program called foo that will read one file called data.foo and produce two files named data.c and data.h ....
Read more >
Set multiple outputs in Webpack
After we build the default config variable, we can create as many configurations we need. In my example I only wrote two —...
Read more >
Output
Configuring the output configuration options tells webpack how to write the compiled files to disk. Note that, while there can be multiple entry...
Read more >
Developers - Multiple entries to output multiple build files -
Current Behavior. When building source with multiple entries, using --entry src/**.ts the build only uses the source of the first file it finds...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found