unbuild icon indicating copy to clipboard operation
unbuild copied to clipboard

feat: support jiti babel plugins config in stubOptions

Open qq15725 opened this issue 1 year ago โ€ข 0 comments

โ“ Type of change

  • [ ] ๐Ÿ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • [ ] ๐Ÿž Bug fix (a non-breaking change that fixes an issue)
  • [ ] ๐Ÿ‘Œ Enhancement (improving an existing functionality like performance)
  • [x] โœจ New feature (a non-breaking change that adds functionality)
  • [ ] ๐Ÿงน Chore (updates to the build process or auxiliary tools and libraries)
  • [ ] โš ๏ธ Breaking change (fix or feature that would cause existing functionality to change)

๐Ÿ“š Description

build.config.ts

{
  stubOptions: {
    jiti: {
      transformOptions: {
        babel: {
          plugins: [
            ["@babel/plugin-transform-class-properties"],
          ],
        },
      },
    },
  },
}

run unbuild --stub

index.cjs

const jiti = require("xxx/node_modules/.pnpm/[email protected]/node_modules/jiti/lib/index.js")
const plugin0 = require("@babel/plugin-transform-class-properties")

const _jiti = jiti(null, {
  "esmResolve": true,
  "interopDefault": true,
  "alias": {
    "fixture": "xxx/test/fixture"
  },
  "transformOptions": {
    "babel": {
      "plugins": [[plugin0]]
    }
  }
})

/** @type {import("xxx/test/fixture/src/index")} */
module.exports = _jiti("xxx/test/fixture/src/index.ts")

index.mjs

import jiti from "xxx/node_modules/.pnpm/[email protected]/node_modules/jiti/lib/index.js";
import plugin0 from "@babel/plugin-transform-class-properties"

const _jiti = jiti(null, {
  "esmResolve": true,
  "interopDefault": true,
  "alias": {
    "fixture": "xxx/test/fixture"
  },
  "transformOptions": {
    "babel": {
      "plugins": [[plugin0]]
    }
  }
})

/** @type {import("xxx/test/fixture/src/index")} */
const _module = await _jiti.import("xxx/test/fixture/src/index.ts");

export default _module;
export const foo = _module.foo;
export const baz = _module.baz;

๐Ÿ“ Checklist

  • [ ] I have linked an issue or discussion.
  • [ ] I have updated the documentation accordingly.

qq15725 avatar Feb 01 '24 09:02 qq15725