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

feat: support custom jiti plugins for stub mode #368

Merged
merged 4 commits into from
Jun 4, 2024

Conversation

qq15725
Copy link
Contributor

@qq15725 qq15725 commented Feb 1, 2024

❓ 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)
  • ✨ 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/jiti@1.21.0/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/jiti@1.21.0/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 qq15725 changed the title Support jiti babel plugins config in stubOptions feat: support jiti babel plugins config in stubOptions Feb 1, 2024
@pi0 pi0 changed the title feat: support jiti babel plugins config in stubOptions feat: support custom jiti plugins for stub mode Jun 4, 2024
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@pi0 pi0 merged commit 7926335 into unjs:main Jun 4, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants