Skip to content

NullVoxPopuli/ember-classic-import-meta-glob

Repository files navigation

ember-classic-import-meta-glob

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

Note

There is a build-time implementation planned, but is not released yet -- the build time implementation aims to be 100% faithful to the import.meta.glob provided by vite and other tools -- this accuracy is not possible in a runtime solution as this library implements. If you don't yet need import.meta.glob, you may want to hold off until that build-time implementation built -- for context on the current state of import.meta.glob support in ember-cli, see this summary comparing this runtime implementation with an initial spike of a build time implementation.

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.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors