UNPKG

@marko/vite

Version:
31 lines (30 loc) 1.17 kB
import type { PluginObj } from "@babel/core"; /** * This plugin is designed to transform imports within Marko files to interop between ESM and CJS. * In Node, ESM files cannot reliably use named imports and default imports from CJS files. * Additionally, modules which are transpiled from ESM to CJS will use a `__esModule` property to * signal that the consuming ESM code should treat `exports.default` as the default import. * This plugin only modifies imports it determined to be for CJS modules * * Examples * 1. Source: ```import { bar as baz } from 'foo';``` * Becomes:``` * import _foo from 'foo'; * const { bar: baz } = _foo * ``` * * 2. Source: ```import myFoo from 'foo';``` * Becomes: ``` * import * as _myFoo from 'foo'; * const myFoo = _myFoo?.__esModule ? _myFoo.default : _myFoo; * ``` * * 3. Source: ```import foo, * as nsFoo from 'foo';``` * Becomes: ``` * import nsFoo from 'foo'; * const myFoo = nsFoo?.__esModule ? nsFoo.default : nsFoo * ``` */ export default function plugin(options: { filter?: (path: string) => boolean; }): PluginObj;