ember-classic-import-meta-glob

MIT License

Stars
0

ember-classic-import-meta-glob

Implements RFC#939: import.meta.glob for ember-classic (pre-embroider).

Compatibility

See working demos here: https://github.com/NullVoxPopuli/ember-import-meta-glob-demos

Installation

pnpm add ember-classic-import-meta-glob

Usage

Default usage:

// If you type this in your app:
const widgets = import.meta.glob('./widgets/*.js')

// It gets automatically converted into something like this:
const widgets = {
  './widgets/first.js': () => import('./widgets/first.js'),
  './widgets/second.js': () => import('./widgets/second.js'),
}

Example with eager: true

// If you type this in your app:
const widgets = import.meta.glob('./widgets/*.js', { eager: true } )

// It gets automatically converted into something like this:
import * as a from './widgets/first.js';
import * as b from './widgets/first.js';
const widgets = {
  './widgets/first.js': a,
  './widgets/second.js': b,
}

Differences from RFC#939

  • Extensions in the import paths are optional -- this because they do not exist at runtime, and the implementation for this version of import.meta.glob cannot determine what the original file names were.
  • the keys in the return object from glob will not contain file name extensions, because they do not exist at runtime.

For ember-classic, this is meant to ease migration to the new, modern features, reducing the overall diff you'd need if you didn't have entire feature sets that are available to embroider.

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.