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:
const words: string = 'hello'
console.log(words)
Standalone
NODE_OPTIONS="--experimental-loader esm-loader-typescript" node index.ts
Chainable
This loader can be configured, and chained with other loaders, using
node-esm-loader. This should be your only loader handling
Typescript files.
npm install --save-dev node-esm-loader
export default {
loaders: ['esm-loader-typescript'],
}
NODE_OPTIONS="--experimental-loader node-esm-loader" node index.ts
Debug
export default {
loaders: [
{
loader: 'esm-loader-typescript',
options: {
debug: true,
},
},
],
}
License
MIT