JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1295
  • Score
    100M100P100Q106115F
  • License MIT

Chainable ESModule Loader for Typescript

Package Exports

  • esm-loader-typescript
  • esm-loader-typescript/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 (esm-loader-typescript) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

esm-loader-typescript

Node.js ESModule Loader for importing and loading Typescript (.ts) files and transpiling on the fly.

Warning! Using experimental Node.js features and flags, API will likely change. This may be helpful for development and testing, but should not be used in production.

Usage

npm install --save-dev esm-loader-typescript

We want to import a .ts file with Node.js:

// index.ts
const words: string = 'hello'
console.log(words)
// 'hello'

Standalone

# node >= 20.7
cat << EOF > ./register.js
import { register } from 'node:module'
register('esm-loader-typescript', import.meta.url)
EOF
NODE_OPTIONS="--import ./register.js" node index.ts

# node < 20.7
NODE_OPTIONS="--loader esm-loader-typescript" node index.ts

Chainable

This loader can be configured, and chained with other loaders, using node-esm-loader.

npm install --save-dev node-esm-loader
// .loaderrc.js
export default {
  loaders: ['esm-loader-typescript'],
}
# node >= 20.7
NODE_OPTIONS="--import node-esm-loader/register" node index.ts

# node < 20.7
NODE_OPTIONS="--loader node-esm-loader" node index.ts

Options

Config

You may specify a custom TypeScript config filename to use:

// .loaderrc.js
export default {
  loaders: [
    {
      loader: 'esm-loader-typescript',
      options: {
        config: 'tsconfig-custom.json',
      },
    },
  ],
}

Otherwise, if a tsconfig.json file is found, it will be loaded and used.

Debug
// .loaderrc.js
export default {
  loaders: [
    {
      loader: 'esm-loader-typescript',
      options: {
        debug: true,
      },
    },
  ],
}

License

MIT