1.0.9 • Published 6 months ago

esm-loader-import-alias v1.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

esm-loader-import-alias

Node.js ESModule Loader for rewriting import path aliases.

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

Some frameworks will allow aliases in import paths ($lib). This loader helps Node.js handle these aliases:

import { tool } from '$lib/utils.js'

Chainable

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

npm install --save-dev esm-loader-import-alias node-esm-loader
// .loaderrc.js
import { resolve } from 'node:path'

export default {
  loaders: [
    {
      loader: 'esm-loader-import-alias',
      options: {
        aliases: {
          // SvelteKit $lib import path alias example
          '$lib/': `${resolve('src/lib/')}/`,
        },
      },
    },
  ],
}
// index.js
import Component from '$lib/Component.js'
# node >= 20.7
NODE_OPTIONS="--import node-esm-loader/register" node index.js

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

Options

Aliases

See example above.

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

Ordering

In your loader chain:

License

MIT

1.0.9

6 months ago

1.0.8

10 months ago

1.0.7

1 year ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.2

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago