Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Customize jiti optionsΒ #9350

@IlyaSemenov

Description

@IlyaSemenov

Is your feature request related to a problem? Please describe.

My Nuxt server middleware relies on custom babel options. With Nuxt 2.15 and jiti my setup is broken.

I would like to be able to pass custom jiti options object (such as { transformOptions: ... }) to fix that, however, currently Nuxt doesn't allow that. jiti is unilaterally called without any options whatsoever:

https://github.com/nuxt/nuxt.js/blob/2ec62617ced873fef97c73a6d7aa1271911ccfd5/packages/utils/src/cjs.js#L5-L7

Describe the solution you'd like

I would like a new section in nuxt.config.js, either top-level jiti or build.jiti, with jiti options. This is similar to build.babel for that matter.

Example:

const config: NuxtConfig = {
  build: {
    jiti: {
      transformOptions: {
        babel: {
          babelrc: true,
        },
      },
    },
  },
}

Describe alternatives you've considered

I'm going with this at the moment:

const config: NuxtConfig = {
  createRequire: p => {
    return jiti(typeof p === 'string' ? p : p.filename, {
      transformOptions: { ... }
    }
  }
}

This is:
a) undocumented
b) needs boilerplate copy/paste and unneeded knowledge about p.filename
c) possibly unreliable and/or will need more boilerplate for production build

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions