JSPM

  • Created
  • Published
  • Downloads 175
  • Score
    100M100P100Q74585F
  • License MIT

Import .ts, .mjs, .cjs files across environments as JavaScript modules

Package Exports

  • cross-import
  • cross-import/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cross-import) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme


Import .ts, .mjs, .cjs files across environments as JavaScript modules

NPM Version NPM Version NPM package ( download / month ) Follow @mastercorg Github release actions


Solved Problems

As far as is generally known:

  • Cannot import ESM modules in CJS
  • Cannot use ESM dynamic import in CJS
  • Cannot use CJS dynamic require in ESM
  • Cannot import .ts config in .js .cjs .mjs
  • Cannot mix .js .cjs .mjs packages

Getting Started

npm install cross-import

Usage

import crossImport from 'cross-import'
crossImport(
    source: string | fg.Pattern[],
    options?: fg.Options
): any

Import .ts in .js

foo.ts

export * from './bar'
export const foo = 'foo'

bar.ts

export const bar = 'bar'

index.js

crossImport('./foo.ts')
// {"bar": "bar", "foo": "foo"}

And so on...

Import format-multiple JS config

This is often used to read various user-defined configuration files like master.css.ts, next.config.js, vite.config.mjs ...

index.js

crossImport('master.css.{js,ts,cjs,mjs}')
// {"bar": "bar", "foo": "foo"}

Options

Inherited from fast-glob options

{
    cwd: process.cwd()
}

NPM Version