Skip to content

Pattern for separate dev/prod CJS files? #824

@markerikson

Description

@markerikson

We've been using TSDX for Redux Toolkit, which currently generates 3 CommonJS files: index.js, redux-toolkit.cjs.development.js, and redux-toolkit.cjs.production.js.

The index.js file looks like:

if (process.env.NODE_ENV === 'production') {
  module.exports = require('./redux-toolkit.cjs.production.min.js')
} else {
  module.exports = require('./redux-toolkit.cjs.development.js')
}

In package.json, we've got main: ./dist/index.js pointing to that file.

I'm playing around with Microbundle for the first time, and it looks like it isn't really set up to do that kind of pattern. So, questions:

  • Is there a way to get Microbundle to output both dev and prod CJS builds like that?
  • Is that "build both, import the right one at runtime" approach even something we would want?

Curious for any info folks can provide on how to set things up the right way here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions